+ /* Inspect the apps cmd pipe */
+ if (pollfd == apps_cmd_pipe[0]) {
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ ERR("Apps command pipe error");
+ goto error;
+ } else if (revents & LPOLLIN) {
+ /* Empty pipe */
+ ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
+ if (ret < 0 || ret < sizeof(ust_cmd)) {
+ perror("read apps cmd pipe");
+ goto error;
+ }
+
+ /* Register applicaton to the session daemon */
+ ret = ust_app_register(&ust_cmd.reg_msg,
+ ust_cmd.sock);
+ if (ret < 0) {
+ /* Only critical ENOMEM error can be returned here */
+ goto error;
+ }
+
+ ret = ustctl_register_done(ust_cmd.sock);
+ if (ret < 0) {
+ /*
+ * If the registration is not possible, we simply
+ * unregister the apps and continue
+ */
+ ust_app_unregister(ust_cmd.sock);
+ } else {
+ /*
+ * We just need here to monitor the close of the UST
+ * socket and poll set monitor those by default.
+ */
+ ret = lttng_poll_add(&events, ust_cmd.sock, 0);
+ if (ret < 0) {
+ goto error;
+ }
+
+ DBG("Apps with sock %d added to poll set",
+ ust_cmd.sock);
+ }
+ break;
+ }
+ } else {
+ /*
+ * At this point, we know that a registered application made
+ * the event at poll_wait.
+ */
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ /* Removing from the poll set */
+ ret = lttng_poll_del(&events, pollfd);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Socket closed */
+ ust_app_unregister(pollfd);
+ break;
+ }
+ }
+ }
+ }
+
+error:
+ DBG("Application communication apps dying");
+ close(apps_cmd_pipe[0]);
+ close(apps_cmd_pipe[1]);
+
+ lttng_poll_clean(&events);
+
+ return NULL;
+}
+
+/*
+ * Dispatch request from the registration threads to the application
+ * communication thread.
+ */
+static void *thread_dispatch_ust_registration(void *data)
+{
+ int ret;
+ struct cds_wfq_node *node;
+ struct ust_command *ust_cmd = NULL;
+
+ DBG("[thread] Dispatch UST command started");
+
+ while (!dispatch_thread_exit) {
+ /* Atomically prepare the queue futex */
+ futex_nto1_prepare(&ust_cmd_queue.futex);
+
+ do {
+ /* Dequeue command for registration */
+ node = cds_wfq_dequeue_blocking(&ust_cmd_queue.queue);
+ if (node == NULL) {
+ DBG("Waked up but nothing in the UST command queue");
+ /* Continue thread execution */
+ break;
+ }
+
+ ust_cmd = caa_container_of(node, struct ust_command, node);
+
+ DBG("Dispatching UST registration pid:%d ppid:%d uid:%d"
+ " gid:%d sock:%d name:%s (version %d.%d)",
+ ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
+ ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
+ ust_cmd->sock, ust_cmd->reg_msg.name,
+ ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
+ /*
+ * Inform apps thread of the new application registration. This
+ * call is blocking so we can be assured that the data will be read
+ * at some point in time or wait to the end of the world :)
+ */
+ ret = write(apps_cmd_pipe[1], ust_cmd,
+ sizeof(struct ust_command));
+ if (ret < 0) {
+ perror("write apps cmd pipe");
+ if (errno == EBADF) {
+ /*
+ * We can't inform the application thread to process
+ * registration. We will exit or else application
+ * registration will not occur and tracing will never
+ * start.
+ */
+ goto error;
+ }
+ }
+ free(ust_cmd);
+ } while (node != NULL);
+
+ /* Futex wait on queue. Blocking call on futex() */
+ futex_nto1_wait(&ust_cmd_queue.futex);
+ }
+
+error:
+ DBG("Dispatch thread dying");
+ return NULL;
+}
+
+/*
+ * This thread manage application registration.
+ */
+static void *thread_registration_apps(void *data)
+{
+ int sock = 0, i, ret, pollfd;
+ uint32_t revents, nb_fd;
+ struct lttng_poll_event events;
+ /*
+ * Get allocated in this thread, enqueued to a global queue, dequeued and
+ * freed in the manage apps thread.
+ */
+ struct ust_command *ust_cmd = NULL;
+
+ DBG("[thread] Manage application registration started");
+
+ ret = lttcomm_listen_unix_sock(apps_sock);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /*
+ * Pass 2 as size here for the thread quit pipe and apps socket. Nothing
+ * more will be added to this poll set.
+ */
+ ret = create_thread_poll_set(&events, 2);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Add the application registration socket */
+ ret = lttng_poll_add(&events, apps_sock, LPOLLIN | LPOLLRDHUP);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Notify all applications to register */
+ ret = notify_ust_apps(1);
+ if (ret < 0) {
+ ERR("Failed to notify applications or create the wait shared memory.\n"
+ "Execution continues but there might be problem for already\n"
+ "running applications that wishes to register.");
+ }
+
+ while (1) {
+ DBG("Accepting application registration");
+
+ nb_fd = LTTNG_POLL_GETNB(&events);
+
+ /* Inifinite blocking call, waiting for transmission */
+ ret = lttng_poll_wait(&events, -1);
+ if (ret < 0) {
+ goto error;
+ }
+
+ for (i = 0; i < nb_fd; i++) {
+ /* Fetch once the poll data */
+ revents = LTTNG_POLL_GETEV(&events, i);
+ pollfd = LTTNG_POLL_GETFD(&events, i);
+
+ /* Thread quit pipe has been closed. Killing thread. */
+ ret = check_thread_quit_pipe(pollfd, revents);
+ if (ret) {
+ goto error;
+ }
+
+ /* Event on the registration socket */
+ if (pollfd == apps_sock) {
+ if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ ERR("Register apps socket poll error");
+ goto error;
+ } else if (revents & LPOLLIN) {
+ sock = lttcomm_accept_unix_sock(apps_sock);
+ if (sock < 0) {
+ goto error;
+ }
+
+ /* Create UST registration command for enqueuing */
+ ust_cmd = malloc(sizeof(struct ust_command));
+ if (ust_cmd == NULL) {
+ perror("ust command malloc");
+ goto error;
+ }
+
+ /*
+ * Using message-based transmissions to ensure we don't
+ * have to deal with partially received messages.
+ */
+ ret = lttcomm_recv_unix_sock(sock, &ust_cmd->reg_msg,
+ sizeof(struct ust_register_msg));
+ if (ret < 0 || ret < sizeof(struct ust_register_msg)) {
+ if (ret < 0) {
+ perror("lttcomm_recv_unix_sock register apps");
+ } else {
+ ERR("Wrong size received on apps register");
+ }
+ free(ust_cmd);
+ close(sock);
+ continue;
+ }
+
+ ust_cmd->sock = sock;
+
+ DBG("UST registration received with pid:%d ppid:%d uid:%d"
+ " gid:%d sock:%d name:%s (version %d.%d)",
+ ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
+ ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
+ ust_cmd->sock, ust_cmd->reg_msg.name,
+ ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
+
+ /*
+ * Lock free enqueue the registration request. The red pill
+ * has been taken! This apps will be part of the *system*.
+ */
+ cds_wfq_enqueue(&ust_cmd_queue.queue, &ust_cmd->node);
+
+ /*
+ * Wake the registration queue futex. Implicit memory
+ * barrier with the exchange in cds_wfq_enqueue.
+ */
+ futex_nto1_wake(&ust_cmd_queue.futex);
+ }
+ }
+ }
+ }
+
+error:
+ DBG("UST Registration thread dying");
+
+ /* Notify that the registration thread is gone */
+ notify_ust_apps(0);
+
+ close(apps_sock);
+ close(sock);
+ unlink(apps_unix_sock_path);
+
+ lttng_poll_clean(&events);
+
+ return NULL;
+}
+
+/*
+ * Start the thread_manage_kconsumerd. This must be done after a kconsumerd
+ * exec or it will fails.
+ */
+static int spawn_kconsumerd_thread(void)
+{
+ int ret;
+
+ /* Setup semaphore */
+ sem_init(&kconsumerd_sem, 0, 0);
+
+ ret = pthread_create(&kconsumerd_thread, NULL,
+ thread_manage_kconsumerd, (void *) NULL);
+ if (ret != 0) {
+ perror("pthread_create kconsumerd");
+ goto error;
+ }
+
+ /* Wait for the kconsumerd thread to be ready */
+ sem_wait(&kconsumerd_sem);
+
+ if (kconsumerd_pid == 0) {
+ ERR("Kconsumerd did not start");
+ goto error;
+ }
+
+ return 0;
+
+error:
+ ret = LTTCOMM_KERN_CONSUMER_FAIL;
+ return ret;
+}
+
+/*
+ * Join kernel consumer thread
+ */
+static int join_kconsumerd_thread(void)
+{
+ void *status;
+ int ret;
+
+ if (kconsumerd_pid != 0) {
+ ret = kill(kconsumerd_pid, SIGTERM);
+ if (ret) {
+ ERR("Error killing kconsumerd");
+ return ret;
+ }
+ return pthread_join(kconsumerd_thread, &status);
+ } else {
+ return 0;
+ }
+}
+
+/*
+ * Fork and exec a kernel consumer daemon (kconsumerd).
+ *
+ * Return pid if successful else -1.
+ */
+static pid_t spawn_kconsumerd(void)
+{
+ int ret;
+ pid_t pid;
+ const char *verbosity;
+
+ DBG("Spawning kconsumerd");
+
+ pid = fork();
+ if (pid == 0) {
+ /*
+ * Exec kconsumerd.
+ */
+ if (opt_verbose > 1 || opt_verbose_kconsumerd) {
+ verbosity = "--verbose";
+ } else {
+ verbosity = "--quiet";
+ }
+ execl(INSTALL_BIN_PATH "/ltt-kconsumerd",
+ "ltt-kconsumerd", verbosity, NULL);
+ if (errno != 0) {
+ perror("kernel start consumer exec");
+ }
+ exit(EXIT_FAILURE);
+ } else if (pid > 0) {
+ ret = pid;
+ goto error;
+ } else {
+ perror("kernel start consumer fork");
+ ret = -errno;
+ goto error;
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * Spawn the kconsumerd daemon and session daemon thread.
+ */
+static int start_kconsumerd(void)
+{
+ int ret;
+
+ pthread_mutex_lock(&kconsumerd_pid_mutex);
+ if (kconsumerd_pid != 0) {
+ pthread_mutex_unlock(&kconsumerd_pid_mutex);
+ goto end;
+ }
+
+ ret = spawn_kconsumerd();
+ if (ret < 0) {
+ ERR("Spawning kconsumerd failed");
+ ret = LTTCOMM_KERN_CONSUMER_FAIL;
+ pthread_mutex_unlock(&kconsumerd_pid_mutex);
+ goto error;
+ }
+
+ /* Setting up the global kconsumerd_pid */
+ kconsumerd_pid = ret;
+ pthread_mutex_unlock(&kconsumerd_pid_mutex);
+
+ DBG("Kconsumerd pid %d", ret);
+
+ DBG("Spawning kconsumerd thread");
+ ret = spawn_kconsumerd_thread();
+ if (ret < 0) {
+ ERR("Fatal error spawning kconsumerd thread");
+ goto error;
+ }
+
+end:
+ return 0;
+
+error:
+ return ret;
+}
+
+/*
+ * modprobe_kernel_modules
+ */
+static int modprobe_kernel_modules(void)
+{
+ int ret = 0, i;
+ char modprobe[256];
+
+ for (i = 0; i < ARRAY_SIZE(kernel_modules_list); i++) {
+ ret = snprintf(modprobe, sizeof(modprobe),
+ "/sbin/modprobe %s%s",
+ kernel_modules_list[i].required ? "" : "--quiet ",
+ kernel_modules_list[i].name);
+ if (ret < 0) {
+ perror("snprintf modprobe");
+ goto error;
+ }
+ modprobe[sizeof(modprobe) - 1] = '\0';
+ ret = system(modprobe);
+ if (ret == -1) {
+ ERR("Unable to launch modprobe for module %s",
+ kernel_modules_list[i].name);
+ } else if (kernel_modules_list[i].required
+ && WEXITSTATUS(ret) != 0) {
+ ERR("Unable to load module %s",
+ kernel_modules_list[i].name);
+ } else {
+ DBG("Modprobe successfully %s",
+ kernel_modules_list[i].name);
+ }
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * mount_debugfs
+ */
+static int mount_debugfs(char *path)
+{
+ int ret;
+ char *type = "debugfs";
+
+ ret = mkdir_recursive(path, S_IRWXU | S_IRWXG, geteuid(), getegid());
+ if (ret < 0) {
+ PERROR("Cannot create debugfs path");
+ goto error;
+ }
+
+ ret = mount(type, path, type, 0, NULL);
+ if (ret < 0) {
+ PERROR("Cannot mount debugfs");
+ goto error;
+ }
+
+ DBG("Mounted debugfs successfully at %s", path);
+
+error:
+ return ret;
+}
+
+/*
+ * Setup necessary data for kernel tracer action.
+ */
+static void init_kernel_tracer(void)
+{
+ int ret;
+ char *proc_mounts = "/proc/mounts";
+ char line[256];
+ char *debugfs_path = NULL, *lttng_path = NULL;
+ FILE *fp;
+
+ /* Detect debugfs */
+ fp = fopen(proc_mounts, "r");
+ if (fp == NULL) {
+ ERR("Unable to probe %s", proc_mounts);
+ goto error;
+ }
+
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ if (strstr(line, "debugfs") != NULL) {
+ /* Remove first string */
+ strtok(line, " ");
+ /* Dup string here so we can reuse line later on */
+ debugfs_path = strdup(strtok(NULL, " "));
+ DBG("Got debugfs path : %s", debugfs_path);
+ break;
+ }
+ }
+
+ fclose(fp);
+
+ /* Mount debugfs if needded */
+ if (debugfs_path == NULL) {
+ ret = asprintf(&debugfs_path, "/mnt/debugfs");
+ if (ret < 0) {
+ perror("asprintf debugfs path");
+ goto error;
+ }
+ ret = mount_debugfs(debugfs_path);
+ if (ret < 0) {
+ perror("Cannot mount debugfs");
+ goto error;
+ }
+ }
+
+ /* Modprobe lttng kernel modules */
+ ret = modprobe_kernel_modules();
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Setup lttng kernel path */
+ ret = asprintf(<tng_path, "%s/lttng", debugfs_path);
+ if (ret < 0) {
+ perror("asprintf lttng path");
+ goto error;
+ }
+
+ /* Open debugfs lttng */
+ kernel_tracer_fd = open(lttng_path, O_RDWR);
+ if (kernel_tracer_fd < 0) {
+ DBG("Failed to open %s", lttng_path);
+ goto error;
+ }
+
+ free(lttng_path);
+ free(debugfs_path);
+ DBG("Kernel tracer fd %d", kernel_tracer_fd);
+ return;
+
+error:
+ if (lttng_path) {
+ free(lttng_path);
+ }
+ if (debugfs_path) {
+ free(debugfs_path);
+ }
+ WARN("No kernel tracer available");
+ kernel_tracer_fd = 0;
+ return;
+}
+
+/*
+ * Init tracing by creating trace directory and sending fds kernel consumer.
+ */
+static int init_kernel_tracing(struct ltt_kernel_session *session)
+{
+ int ret = 0;
+
+ if (session->kconsumer_fds_sent == 0) {
+ /*
+ * Assign default kernel consumer socket if no consumer assigned to the
+ * kernel session. At this point, it's NOT suppose to be 0 but this is
+ * an extra security check.
+ */
+ if (session->consumer_fd == 0) {
+ session->consumer_fd = kconsumerd_cmd_sock;
+ }
+
+ ret = send_kconsumerd_fds(session);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONSUMER_FAIL;
+ goto error;
+ }
+
+ session->kconsumer_fds_sent = 1;
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * Create an UST session and add it to the session ust list.
+ */
+static int create_ust_session(struct ltt_session *session,
+ struct lttng_domain *domain)
+{
+ int ret;
+ struct ltt_ust_session *lus;
+ struct ust_app *app;
+
+ switch (domain->type) {
+ case LTTNG_DOMAIN_UST_PID:
+ app = ust_app_get_by_pid(domain->attr.pid);
+ if (app == NULL) {
+ ret = LTTCOMM_APP_NOT_FOUND;
+ goto error;
+ }
+ break;
+ default:
+ goto error;
+ }
+
+ DBG("Creating UST session");
+
+ lus = trace_ust_create_session(session->path, domain->attr.pid, domain);
+ if (lus == NULL) {
+ ret = LTTCOMM_UST_SESS_FAIL;
+ goto error;
+ }
+
+ ret = mkdir_recursive(lus->path, S_IRWXU | S_IRWXG,
+ geteuid(), allowed_group());
+ if (ret < 0) {
+ if (ret != -EEXIST) {
+ ERR("Trace directory creation error");
+ ret = LTTCOMM_UST_SESS_FAIL;
+ goto error;
+ }
+ }
+
+ /* Create session on the UST tracer */
+ ret = ustctl_create_session(app->sock, lus);
+ if (ret < 0) {
+ ret = LTTCOMM_UST_SESS_FAIL;
+ goto error;
+ }
+
+ cds_list_add(&lus->list, &session->ust_session_list.head);
+ session->ust_session_list.count++;
+
+ return LTTCOMM_OK;
+
+error:
+ free(lus);
+ return ret;
+}
+
+/*
+ * Create a kernel tracer session then create the default channel.
+ */
+static int create_kernel_session(struct ltt_session *session)
+{
+ int ret;
+
+ DBG("Creating kernel session");
+
+ ret = kernel_create_session(session, kernel_tracer_fd);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_SESS_FAIL;
+ goto error;
+ }
+
+ /* Set kernel consumer socket fd */
+ if (kconsumerd_cmd_sock) {
+ session->kernel_session->consumer_fd = kconsumerd_cmd_sock;
+ }
+
+ ret = mkdir_recursive(session->kernel_session->trace_path,
+ S_IRWXU | S_IRWXG, geteuid(), allowed_group());
+ if (ret < 0) {
+ if (ret != -EEXIST) {
+ ERR("Trace directory creation error");
+ goto error;
+ }
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * Using the session list, filled a lttng_session array to send back to the
+ * client for session listing.
+ *
+ * The session list lock MUST be acquired before calling this function. Use
+ * session_lock_list() and session_unlock_list().
+ */
+static void list_lttng_sessions(struct lttng_session *sessions)
+{
+ int i = 0;
+ struct ltt_session *session;
+
+ DBG("Getting all available session");
+ /*
+ * Iterate over session list and append data after the control struct in
+ * the buffer.
+ */
+ cds_list_for_each_entry(session, &session_list_ptr->head, list) {
+ strncpy(sessions[i].path, session->path, PATH_MAX);
+ sessions[i].path[PATH_MAX - 1] = '\0';
+ strncpy(sessions[i].name, session->name, NAME_MAX);
+ sessions[i].name[NAME_MAX - 1] = '\0';
+ i++;
+ }
+}
+
+/*
+ * Fill lttng_channel array of all channels.
+ */
+static void list_lttng_channels(struct ltt_session *session,
+ struct lttng_channel *channels)
+{
+ int i = 0;
+ struct ltt_kernel_channel *kchan;
+
+ DBG("Listing channels for session %s", session->name);
+
+ /* Kernel channels */
+ if (session->kernel_session != NULL) {
+ cds_list_for_each_entry(kchan,
+ &session->kernel_session->channel_list.head, list) {
+ /* Copy lttng_channel struct to array */
+ memcpy(&channels[i], kchan->channel, sizeof(struct lttng_channel));
+ channels[i].enabled = kchan->enabled;
+ i++;
+ }
+ }
+
+ /* TODO: Missing UST listing */
+}
+
+/*
+ * Fill lttng_event array of all events in the channel.
+ */
+static void list_lttng_events(struct ltt_kernel_channel *kchan,
+ struct lttng_event *events)
+{
+ /*
+ * TODO: This is ONLY kernel. Need UST support.
+ */
+ int i = 0;
+ struct ltt_kernel_event *event;
+
+ DBG("Listing events for channel %s", kchan->channel->name);
+
+ /* Kernel channels */
+ cds_list_for_each_entry(event, &kchan->events_list.head , list) {
+ strncpy(events[i].name, event->event->name, LTTNG_SYMBOL_NAME_LEN);
+ events[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+ events[i].enabled = event->enabled;
+ switch (event->event->instrumentation) {
+ case LTTNG_KERNEL_TRACEPOINT:
+ events[i].type = LTTNG_EVENT_TRACEPOINT;
+ break;
+ case LTTNG_KERNEL_KPROBE:
+ case LTTNG_KERNEL_KRETPROBE:
+ events[i].type = LTTNG_EVENT_PROBE;
+ memcpy(&events[i].attr.probe, &event->event->u.kprobe,
+ sizeof(struct lttng_kernel_kprobe));
+ break;
+ case LTTNG_KERNEL_FUNCTION:
+ events[i].type = LTTNG_EVENT_FUNCTION;
+ memcpy(&events[i].attr.ftrace, &event->event->u.ftrace,
+ sizeof(struct lttng_kernel_function));
+ break;
+ case LTTNG_KERNEL_NOOP:
+ events[i].type = LTTNG_EVENT_NOOP;
+ break;
+ case LTTNG_KERNEL_SYSCALL:
+ events[i].type = LTTNG_EVENT_SYSCALL;
+ break;
+ case LTTNG_KERNEL_ALL:
+ assert(0);
+ break;
+ }
+ i++;
+ }
+}
+
+/*
+ * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
+ */
+static int cmd_disable_channel(struct ltt_session *session,
+ int domain, char *channel_name)
+{
+ int ret;
+
+ switch (domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ ret = channel_kernel_disable(session->kernel_session,
+ channel_name);
+ if (ret != LTTCOMM_OK) {
+ goto error;
+ }
+
+ kernel_wait_quiescent(kernel_tracer_fd);
+ break;
+ case LTTNG_DOMAIN_UST_PID:
+ break;
+ default:
+ ret = LTTCOMM_UNKNOWN_DOMAIN;
+ goto error;
+ }
+
+ ret = LTTCOMM_OK;
+
+error:
+ return ret;
+}
+
+/*
+ * Copy channel from attributes and set it in the application channel list.
+ */
+static int copy_ust_channel_to_app(struct ltt_ust_session *usess,
+ struct lttng_channel *attr, struct ust_app *app)
+{
+ int ret;
+ struct ltt_ust_channel *uchan, *new_chan;
+
+ uchan = trace_ust_get_channel_by_name(attr->name, usess);
+ if (uchan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ new_chan = trace_ust_create_channel(attr, usess->path);
+ if (new_chan == NULL) {
+ PERROR("malloc ltt_ust_channel");
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ ret = channel_ust_copy(new_chan, uchan);
+ if (ret < 0) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ /* Add channel to the ust app channel list */
+ cds_list_add(&new_chan->list, &app->channels.head);
+ app->channels.count++;
+
+error:
+ return ret;
+}
+
+/*
+ * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
+ */
+static int cmd_enable_channel(struct ltt_session *session,
+ struct lttng_domain *domain, struct lttng_channel *attr)
+{
+ int ret;
+
+ switch (domain->type) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
+ struct ltt_kernel_channel *kchan;
+
+ kchan = trace_kernel_get_channel_by_name(attr->name,
+ session->kernel_session);
+ if (kchan == NULL) {
+ ret = channel_kernel_create(session->kernel_session,
+ attr, kernel_poll_pipe[1]);
+ } else {
+ ret = channel_kernel_enable(session->kernel_session, kchan);
+ }
+
+ if (ret != LTTCOMM_OK) {
+ goto error;
+ }
+
+ kernel_wait_quiescent(kernel_tracer_fd);
+ break;
+ }
+ case LTTNG_DOMAIN_UST_PID:
+ {
+ int sock;
+ struct ltt_ust_channel *uchan;
+ struct ltt_ust_session *usess;
+ struct ust_app *app;
+
+ usess = trace_ust_get_session_by_pid(&session->ust_session_list,
+ domain->attr.pid);
+ if (usess == NULL) {
+ ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+ goto error;
+ }
+
+ app = ust_app_get_by_pid(domain->attr.pid);
+ if (app == NULL) {
+ ret = LTTCOMM_APP_NOT_FOUND;
+ goto error;
+ }
+ sock = app->sock;