+
+static bool shutdown_application_notification_thread(void *data)
+{
+ struct thread_notifiers *notifiers = data;
+ const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe);
+
+ return notify_thread_pipe(write_fd) == 1;
+}
+
+static void cleanup_application_notification_thread(void *data)
+{
+ struct thread_notifiers *notifiers = data;
+
+ lttng_pipe_destroy(notifiers->quit_pipe);
+ free(notifiers);
+}
+
+bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd)
+{
+ struct lttng_thread *thread;
+ struct thread_notifiers *notifiers;
+ struct lttng_pipe *quit_pipe;
+
+ notifiers = zmalloc(sizeof(*notifiers));
+ if (!notifiers) {
+ goto error;
+ }
+ notifiers->apps_cmd_notify_pipe_read_fd = apps_cmd_notify_pipe_read_fd;
+
+ quit_pipe = lttng_pipe_open(FD_CLOEXEC);
+ if (!quit_pipe) {
+ goto error;
+ }
+ notifiers->quit_pipe = quit_pipe;
+
+ thread = lttng_thread_create("Application notification",
+ thread_application_notification,
+ shutdown_application_notification_thread,
+ cleanup_application_notification_thread,
+ notifiers);
+ if (!thread) {
+ goto error;
+ }
+ lttng_thread_put(thread);
+ return true;
+error:
+ cleanup_application_notification_thread(notifiers);
+ return false;
+}