- ret = LTTCOMM_UNKNOWN_DOMAIN;
- goto error;
- }
-
- DBG("Creating UST session");
-
- lus = trace_ust_create_session(session->path, session->id, domain);
- if (lus == NULL) {
- ret = LTTCOMM_UST_SESS_FAIL;
- goto error;
- }
-
- ret = run_as_mkdir_recursive(lus->pathname, S_IRWXU | S_IRWXG,
- session->uid, session->gid);
- if (ret < 0) {
- if (ret != -EEXIST) {
- ERR("Trace directory creation error");
- ret = LTTCOMM_UST_SESS_FAIL;
- goto error;
- }
- }
-
- /* The domain type dictate different actions on session creation */
- switch (domain->type) {
- case LTTNG_DOMAIN_UST:
- /* No ustctl for the global UST domain */
- break;
- default:
- ERR("Unknown UST domain on create session %d", domain->type);
- goto error;
- }
- lus->uid = session->uid;
- lus->gid = session->gid;
- session->ust_session = lus;
-
- 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 (kconsumer_data.cmd_sock) {
- session->kernel_session->consumer_fd = kconsumer_data.cmd_sock;
- }
-
- ret = run_as_mkdir_recursive(session->kernel_session->trace_path,
- S_IRWXU | S_IRWXG, session->uid, session->gid);
- if (ret < 0) {
- if (ret != -EEXIST) {
- ERR("Trace directory creation error");
- goto error;
- }
- }
- session->kernel_session->uid = session->uid;
- session->kernel_session->gid = session->gid;
-
-error:
- return ret;
-}
-
-/*
- * Check if the UID or GID match the session. Root user has access to all
- * sessions.
- */
-static int session_access_ok(struct ltt_session *session, uid_t uid, gid_t gid)
-{
- if (uid != session->uid && gid != session->gid && uid != 0) {
- return 0;
- } else {
- return 1;
- }
-}
-
-static unsigned int lttng_sessions_count(uid_t uid, gid_t gid)
-{
- unsigned int i = 0;
- struct ltt_session *session;
-
- DBG("Counting number of available session for UID %d GID %d",
- uid, gid);
- cds_list_for_each_entry(session, &session_list_ptr->head, list) {
- /*
- * Only list the sessions the user can control.
- */
- if (!session_access_ok(session, uid, gid)) {
- continue;
- }
- i++;
- }
- return i;
-}
-
-/*
- * 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, uid_t uid,
- gid_t gid)
-{
- unsigned int i = 0;
- struct ltt_session *session;
-
- DBG("Getting all available session for UID %d GID %d",
- uid, gid);
- /*
- * 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) {
- /*
- * Only list the sessions the user can control.
- */
- if (!session_access_ok(session, uid, gid)) {
- continue;
- }
- 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';
- sessions[i].enabled = session->enabled;
- i++;
- }
-}
-
-/*
- * Fill lttng_channel array of all channels.
- */
-static void list_lttng_channels(int domain, struct ltt_session *session,
- struct lttng_channel *channels)
-{
- int i = 0;
- struct ltt_kernel_channel *kchan;
-
- DBG("Listing channels for session %s", session->name);
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* 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++;
- }
- }
- break;
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_ht_iter iter;
- struct ltt_ust_channel *uchan;
-
- cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
- &iter.iter, uchan, node.node) {
- strncpy(channels[i].name, uchan->name, LTTNG_SYMBOL_NAME_LEN);
- channels[i].attr.overwrite = uchan->attr.overwrite;
- channels[i].attr.subbuf_size = uchan->attr.subbuf_size;
- channels[i].attr.num_subbuf = uchan->attr.num_subbuf;
- channels[i].attr.switch_timer_interval =
- uchan->attr.switch_timer_interval;
- channels[i].attr.read_timer_interval =
- uchan->attr.read_timer_interval;
- channels[i].enabled = uchan->enabled;
- switch (uchan->attr.output) {
- case LTTNG_UST_MMAP:
- default:
- channels[i].attr.output = LTTNG_EVENT_MMAP;
- break;
- }
- i++;
- }
- break;
- }
- default:
- break;
- }
-}
-
-/*
- * Create a list of ust global domain events.
- */
-static int list_lttng_ust_global_events(char *channel_name,
- struct ltt_ust_domain_global *ust_global, struct lttng_event **events)
-{
- int i = 0, ret = 0;
- unsigned int nb_event = 0;
- struct lttng_ht_iter iter;
- struct lttng_ht_node_str *node;
- struct ltt_ust_channel *uchan;
- struct ltt_ust_event *uevent;
- struct lttng_event *tmp;
-
- DBG("Listing UST global events for channel %s", channel_name);
-
- rcu_read_lock();
-
- lttng_ht_lookup(ust_global->channels, (void *)channel_name, &iter);
- node = lttng_ht_iter_get_node_str(&iter);
- if (node == NULL) {
- ret = -LTTCOMM_UST_CHAN_NOT_FOUND;
- goto error;
- }
-
- uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node);
-
- nb_event += lttng_ht_get_count(uchan->events);
-
- if (nb_event == 0) {
- ret = nb_event;
- goto error;
- }
-
- DBG3("Listing UST global %d events", nb_event);
-
- tmp = zmalloc(nb_event * sizeof(struct lttng_event));
- if (tmp == NULL) {
- ret = -LTTCOMM_FATAL;
- goto error;
- }
-
- cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
- strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN);
- tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
- tmp[i].enabled = uevent->enabled;
- switch (uevent->attr.instrumentation) {
- case LTTNG_UST_TRACEPOINT:
- tmp[i].type = LTTNG_EVENT_TRACEPOINT;
- break;
- case LTTNG_UST_PROBE:
- tmp[i].type = LTTNG_EVENT_PROBE;
- break;
- case LTTNG_UST_FUNCTION:
- tmp[i].type = LTTNG_EVENT_FUNCTION;
- break;
- }
- tmp[i].loglevel = uevent->attr.loglevel;
- switch (uevent->attr.loglevel_type) {
- case LTTNG_UST_LOGLEVEL_ALL:
- tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
- break;
- case LTTNG_UST_LOGLEVEL_RANGE:
- tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
- break;
- case LTTNG_UST_LOGLEVEL_SINGLE:
- tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
- break;
- }
- i++;
- }
-
- ret = nb_event;
- *events = tmp;
-
-error:
- rcu_read_unlock();
- return ret;
-}
-
-/*
- * Fill lttng_event array of all kernel events in the channel.
- */
-static int list_lttng_kernel_events(char *channel_name,
- struct ltt_kernel_session *kernel_session, struct lttng_event **events)
-{
- int i = 0, ret;
- unsigned int nb_event;
- struct ltt_kernel_event *event;
- struct ltt_kernel_channel *kchan;
-
- kchan = trace_kernel_get_channel_by_name(channel_name, kernel_session);
- if (kchan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
- }
-
- nb_event = kchan->event_count;
-
- DBG("Listing events for channel %s", kchan->channel->name);
-
- if (nb_event == 0) {
- ret = nb_event;
- goto error;
- }
-
- *events = zmalloc(nb_event * sizeof(struct lttng_event));
- if (*events == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- /* 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++;
- }
-
- return nb_event;
-
-error:
- return ret;
-}
-
-/*
- * 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;
- struct ltt_ust_session *usess;
-
- usess = session->ust_session;
-
- 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:
- {
- struct ltt_ust_channel *uchan;
- struct lttng_ht *chan_ht;
-
- chan_ht = usess->domain_global.channels;
-
- uchan = trace_ust_find_channel_by_name(chan_ht, channel_name);
- if (uchan == NULL) {
- ret = LTTCOMM_UST_CHAN_NOT_FOUND;
- goto error;
- }
-
- ret = channel_ust_disable(usess, domain, uchan);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
-#endif
- default:
- ret = LTTCOMM_UNKNOWN_DOMAIN;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
- */
-static int cmd_enable_channel(struct ltt_session *session,
- int domain, struct lttng_channel *attr)
-{
- int ret;
- struct ltt_ust_session *usess = session->ust_session;
- struct lttng_ht *chan_ht;
-
- DBG("Enabling channel %s for session %s", attr->name, session->name);
-
- switch (domain) {
- 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:
- {
- struct ltt_ust_channel *uchan;
-
- chan_ht = usess->domain_global.channels;
-
- uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
- if (uchan == NULL) {
- ret = channel_ust_create(usess, domain, attr);
- } else {
- ret = channel_ust_enable(usess, domain, uchan);
- }
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
-#endif
- default:
- ret = LTTCOMM_UNKNOWN_DOMAIN;
- goto error;
- }
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_DISABLE_EVENT processed by the client thread.
- */
-static int cmd_disable_event(struct ltt_session *session, int domain,
- char *channel_name, char *event_name)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct ltt_kernel_channel *kchan;
- struct ltt_kernel_session *ksess;
-
- ksess = session->kernel_session;
-
- kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
- if (kchan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
- }
-
- ret = event_kernel_disable_tracepoint(ksess, kchan, event_name);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- kernel_wait_quiescent(kernel_tracer_fd);
- break;
- }
- case LTTNG_DOMAIN_UST:
- {
- struct ltt_ust_channel *uchan;
- struct ltt_ust_session *usess;
-
- usess = session->ust_session;
-
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- channel_name);
- if (uchan == NULL) {
- ret = LTTCOMM_UST_CHAN_NOT_FOUND;
- goto error;
- }
-
- ret = event_ust_disable_tracepoint(usess, domain, uchan, event_name);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- DBG3("Disable UST event %s in channel %s completed", event_name,
- channel_name);
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_DISABLE_ALL_EVENT processed by the client thread.
- */
-static int cmd_disable_event_all(struct ltt_session *session, int domain,
- char *channel_name)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct ltt_kernel_session *ksess;
- struct ltt_kernel_channel *kchan;
-
- ksess = session->kernel_session;
-
- kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
- if (kchan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
- }
-
- ret = event_kernel_disable_all(ksess, kchan);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- kernel_wait_quiescent(kernel_tracer_fd);
- break;
- }
- case LTTNG_DOMAIN_UST:
- {
- struct ltt_ust_session *usess;
- struct ltt_ust_channel *uchan;
-
- usess = session->ust_session;
-
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- channel_name);
- if (uchan == NULL) {
- ret = LTTCOMM_UST_CHAN_NOT_FOUND;
- goto error;
- }
-
- ret = event_ust_disable_all_tracepoints(usess, domain, uchan);
- if (ret != 0) {
- goto error;
- }
-
- DBG3("Disable all UST events in channel %s completed", channel_name);
-
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_ADD_CONTEXT processed by the client thread.
- */
-static int cmd_add_context(struct ltt_session *session, int domain,
- char *channel_name, char *event_name, struct lttng_event_context *ctx)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* Add kernel context to kernel tracer */
- ret = context_kernel_add(session->kernel_session, ctx,
- event_name, channel_name);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- break;
- case LTTNG_DOMAIN_UST:
- {
- struct ltt_ust_session *usess = session->ust_session;
-
- ret = context_ust_add(usess, domain, ctx, event_name, channel_name);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_ENABLE_EVENT processed by the client thread.
- */
-static int cmd_enable_event(struct ltt_session *session, int domain,
- char *channel_name, struct lttng_event *event)
-{
- int ret;
- struct lttng_channel *attr;
- struct ltt_ust_session *usess = session->ust_session;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct ltt_kernel_channel *kchan;
-
- kchan = trace_kernel_get_channel_by_name(channel_name,
- session->kernel_session);
- if (kchan == NULL) {
- attr = channel_new_default_attr(domain);
- if (attr == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- snprintf(attr->name, NAME_MAX, "%s", channel_name);
-
- /* This call will notify the kernel thread */
- ret = channel_kernel_create(session->kernel_session,
- attr, kernel_poll_pipe[1]);
- if (ret != LTTCOMM_OK) {
- free(attr);
- goto error;
- }
- free(attr);
- }
-
- /* Get the newly created kernel channel pointer */
- kchan = trace_kernel_get_channel_by_name(channel_name,
- session->kernel_session);
- if (kchan == NULL) {
- /* This sould not happen... */
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- ret = event_kernel_enable_tracepoint(session->kernel_session, kchan,
- event);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- kernel_wait_quiescent(kernel_tracer_fd);
- break;
- }
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_channel *attr;
- struct ltt_ust_channel *uchan;
-
- /* Get channel from global UST domain */
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- channel_name);
- if (uchan == NULL) {
- /* Create default channel */
- attr = channel_new_default_attr(domain);
- if (attr == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- snprintf(attr->name, NAME_MAX, "%s", channel_name);
- attr->name[NAME_MAX - 1] = '\0';
-
- ret = channel_ust_create(usess, domain, attr);
- if (ret != LTTCOMM_OK) {
- free(attr);
- goto error;
- }
- free(attr);
-
- /* Get the newly created channel reference back */
- uchan = trace_ust_find_channel_by_name(
- usess->domain_global.channels, channel_name);
- if (uchan == NULL) {
- /* Something is really wrong */
- ret = LTTCOMM_FATAL;
- goto error;
- }
- }
-
- /* At this point, the session and channel exist on the tracer */
- ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread.
- */
-static int cmd_enable_event_all(struct ltt_session *session, int domain,
- char *channel_name, int event_type)
-{
- int ret;
- struct ltt_kernel_channel *kchan;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- kchan = trace_kernel_get_channel_by_name(channel_name,
- session->kernel_session);
- if (kchan == NULL) {
- /* This call will notify the kernel thread */
- ret = channel_kernel_create(session->kernel_session, NULL,
- kernel_poll_pipe[1]);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- /* Get the newly created kernel channel pointer */
- kchan = trace_kernel_get_channel_by_name(channel_name,
- session->kernel_session);
- if (kchan == NULL) {
- /* This sould not happen... */
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- }
-
- switch (event_type) {
- case LTTNG_EVENT_SYSCALL:
- ret = event_kernel_enable_all_syscalls(session->kernel_session,
- kchan, kernel_tracer_fd);
- break;
- case LTTNG_EVENT_TRACEPOINT:
- /*
- * This call enables all LTTNG_KERNEL_TRACEPOINTS and
- * events already registered to the channel.
- */
- ret = event_kernel_enable_all_tracepoints(session->kernel_session,
- kchan, kernel_tracer_fd);
- break;
- case LTTNG_EVENT_ALL:
- /* Enable syscalls and tracepoints */
- ret = event_kernel_enable_all(session->kernel_session,
- kchan, kernel_tracer_fd);
- break;
- default:
- ret = LTTCOMM_KERN_ENABLE_FAIL;
- goto error;
- }
-
- /* Manage return value */
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- kernel_wait_quiescent(kernel_tracer_fd);
- break;
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_channel *attr;
- struct ltt_ust_channel *uchan;
- struct ltt_ust_session *usess = session->ust_session;
-
- /* Get channel from global UST domain */
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- channel_name);
- if (uchan == NULL) {
- /* Create default channel */
- attr = channel_new_default_attr(domain);
- if (attr == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- snprintf(attr->name, NAME_MAX, "%s", channel_name);
- attr->name[NAME_MAX - 1] = '\0';
-
- /* Use the internal command enable channel */
- ret = channel_ust_create(usess, domain, attr);
- if (ret != LTTCOMM_OK) {
- free(attr);
- goto error;
- }
- free(attr);
-
- /* Get the newly created channel reference back */
- uchan = trace_ust_find_channel_by_name(
- usess->domain_global.channels, channel_name);
- if (uchan == NULL) {
- /* Something is really wrong */
- ret = LTTCOMM_FATAL;
- goto error;
- }
- }
-
- /* At this point, the session and channel exist on the tracer */
-
- switch (event_type) {
- case LTTNG_EVENT_ALL:
- case LTTNG_EVENT_TRACEPOINT:
- ret = event_ust_enable_all_tracepoints(usess, domain, uchan);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- break;
- default:
- ret = LTTCOMM_UST_ENABLE_FAIL;
- goto error;
- }
-
- /* Manage return value */
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
- break;
- }
-#if 0
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
- */
-static ssize_t cmd_list_tracepoints(int domain, struct lttng_event **events)
-{
- int ret;
- ssize_t nb_events = 0;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- nb_events = kernel_list_events(kernel_tracer_fd, events);
- if (nb_events < 0) {
- ret = LTTCOMM_KERN_LIST_FAIL;
- goto error;
- }
- break;
- case LTTNG_DOMAIN_UST:
- nb_events = ust_app_list_events(events);
- if (nb_events < 0) {
- ret = LTTCOMM_UST_LIST_FAIL;
- goto error;
- }
- break;
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- return nb_events;
-
-error:
- /* Return negative value to differentiate return code */
- return -ret;
-}
-
-/*
- * Command LTTNG_START_TRACE processed by the client thread.
- */
-static int cmd_start_trace(struct ltt_session *session)
-{
- int ret;
- struct ltt_kernel_session *ksession;
- struct ltt_ust_session *usess;
-
- /* Short cut */
- ksession = session->kernel_session;
- usess = session->ust_session;
-
- if (session->enabled) {
- ret = LTTCOMM_UST_START_FAIL;