- 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;
- }
- if (uevent->filter) {
- tmp[i].filter = 1;
- }
- 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_SET_FILTER processed by the client thread.
- */
-static int cmd_set_filter(struct ltt_session *session, int domain,
- char *channel_name, char *event_name,
- struct lttng_filter_bytecode *bytecode)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- ret = LTTCOMM_FATAL;
- break;
- case LTTNG_DOMAIN_UST:
- {
- struct ltt_ust_session *usess = session->ust_session;
-
- ret = filter_ust_set(usess, domain, bytecode, 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_LIST_TRACEPOINT_FIELDS processed by the client thread.
- */
-static ssize_t cmd_list_tracepoint_fields(int domain,
- struct lttng_event_field **fields)
-{
- int ret;
- ssize_t nb_fields = 0;
-
- switch (domain) {
- case LTTNG_DOMAIN_UST:
- nb_fields = ust_app_list_event_fields(fields);
- if (nb_fields < 0) {
- ret = LTTCOMM_UST_LIST_FAIL;
- goto error;
- }
- break;
- case LTTNG_DOMAIN_KERNEL:
- default: /* fall-through */
- ret = LTTCOMM_UND;
- goto error;
- }
-
- return nb_fields;
-
-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;
- struct ltt_kernel_channel *kchan;
-
- /* Ease our life a bit ;) */
- ksession = session->kernel_session;
- usess = session->ust_session;
-
- if (session->enabled) {
- /* Already started. */
- ret = LTTCOMM_TRACE_ALREADY_STARTED;
- goto error;
- }
-
- session->enabled = 1;
-
- ret = setup_relayd(session);
- if (ret != LTTCOMM_OK) {
- ERR("Error setting up relayd for session %s", session->name);
- goto error;
- }
-
- /* Kernel tracing */
- if (ksession != NULL) {
- /* Open kernel metadata */
- if (ksession->metadata == NULL) {
- ret = kernel_open_metadata(ksession,
- ksession->consumer->dst.trace_path);
- if (ret < 0) {
- ret = LTTCOMM_KERN_META_FAIL;
- goto error;
- }
- }
-
- /* Open kernel metadata stream */
- if (ksession->metadata_stream_fd < 0) {
- ret = kernel_open_metadata_stream(ksession);
- if (ret < 0) {
- ERR("Kernel create metadata stream failed");
- ret = LTTCOMM_KERN_STREAM_FAIL;
- goto error;
- }
- }
-
- /* For each channel */
- cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) {
- if (kchan->stream_count == 0) {
- ret = kernel_open_channel_stream(kchan);
- if (ret < 0) {
- ret = LTTCOMM_KERN_STREAM_FAIL;
- goto error;
- }
- /* Update the stream global counter */
- ksession->stream_count_global += ret;
- }
- }
-
- /* Setup kernel consumer socket and send fds to it */
- ret = init_kernel_tracing(ksession);
- if (ret < 0) {
- ret = LTTCOMM_KERN_START_FAIL;
- goto error;
- }
-
- /* This start the kernel tracing */
- ret = kernel_start_session(ksession);
- if (ret < 0) {
- ret = LTTCOMM_KERN_START_FAIL;
- goto error;
- }
-
- /* Quiescent wait after starting trace */
- kernel_wait_quiescent(kernel_tracer_fd);
- }
-
- /* Flag session that trace should start automatically */
- if (usess) {
- usess->start_trace = 1;
-
- ret = ust_app_start_trace_all(usess);
- if (ret < 0) {
- ret = LTTCOMM_UST_START_FAIL;
- goto error;
- }
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_STOP_TRACE processed by the client thread.
- */
-static int cmd_stop_trace(struct ltt_session *session)
-{
- int ret;
- struct ltt_kernel_channel *kchan;
- 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_TRACE_ALREADY_STOPPED;
- goto error;
- }
-
- session->enabled = 0;
-
- /* Kernel tracer */
- if (ksession != NULL) {
- DBG("Stop kernel tracing");
-
- /* Flush metadata if exist */
- if (ksession->metadata_stream_fd >= 0) {
- ret = kernel_metadata_flush_buffer(ksession->metadata_stream_fd);
- if (ret < 0) {
- ERR("Kernel metadata flush failed");
- }
- }
-
- /* Flush all buffers before stopping */
- cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) {
- ret = kernel_flush_buffer(kchan);
- if (ret < 0) {
- ERR("Kernel flush buffer error");
- }
- }
-
- ret = kernel_stop_session(ksession);
- if (ret < 0) {
- ret = LTTCOMM_KERN_STOP_FAIL;
- goto error;
- }
-
- kernel_wait_quiescent(kernel_tracer_fd);
- }
-
- if (usess) {
- usess->start_trace = 0;
-
- ret = ust_app_stop_trace_all(usess);
- if (ret < 0) {
- ret = LTTCOMM_UST_STOP_FAIL;
- goto error;
- }
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_CREATE_SESSION_URI processed by the client thread.
- */
-static int cmd_create_session_uri(char *name, struct lttng_uri *ctrl_uri,
- struct lttng_uri *data_uri, unsigned int enable_consumer,
- lttng_sock_cred *creds)
-{
- int ret;
- char *path = NULL;
- struct ltt_session *session;
- struct consumer_output *consumer;
-
- /* Verify if the session already exist */
- session = session_find_by_name(name);
- if (session != NULL) {
- ret = LTTCOMM_EXIST_SESS;
- goto error;
- }
-
- /* TODO: validate URIs */
-
- /* Create default consumer output */
- consumer = consumer_create_output(CONSUMER_DST_LOCAL);
- if (consumer == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- strncpy(consumer->subdir, ctrl_uri->subdir, sizeof(consumer->subdir));
- DBG2("Consumer subdir set to %s", consumer->subdir);
-
- switch (ctrl_uri->dtype) {
- case LTTNG_DST_IPV4:
- case LTTNG_DST_IPV6:
- /* Set control URI into consumer output object */
- ret = consumer_set_network_uri(consumer, ctrl_uri);
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- /* Set data URI into consumer output object */
- ret = consumer_set_network_uri(consumer, data_uri);
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- /* Empty path since the session is network */
- path = "";
- break;
- case LTTNG_DST_PATH:
- /* Very volatile pointer. Only used for the create session. */
- path = ctrl_uri->dst.path;
- strncpy(consumer->dst.trace_path, path,
- sizeof(consumer->dst.trace_path));
- break;
- }
-
- /* Set if the consumer is enabled or not */
- consumer->enabled = enable_consumer;
-
- ret = session_create(name, path, LTTNG_SOCK_GET_UID_CRED(creds),
- LTTNG_SOCK_GET_GID_CRED(creds));
- if (ret != LTTCOMM_OK) {
- goto consumer_error;
- }
-
- /* Get the newly created session pointer back */
- session = session_find_by_name(name);
- assert(session);
-
- /* Assign consumer to session */
- session->consumer = consumer;
-
- return LTTCOMM_OK;
-
-consumer_error:
- consumer_destroy_output(consumer);
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_CREATE_SESSION processed by the client thread.
- */
-static int cmd_create_session(char *name, char *path, lttng_sock_cred *creds)
-{
- int ret;
- struct lttng_uri uri;
-
- /* Zeroed temporary URI */
- memset(&uri, 0, sizeof(uri));
-
- uri.dtype = LTTNG_DST_PATH;
- uri.utype = LTTNG_URI_DST;
- strncpy(uri.dst.path, path, sizeof(uri.dst.path));
-
- /* TODO: Strip date-time from path and put it in uri's subdir */
-
- ret = cmd_create_session_uri(name, &uri, NULL, 1, creds);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_DESTROY_SESSION processed by the client thread.
- */
-static int cmd_destroy_session(struct ltt_session *session, char *name)
-{
- int ret;
-
- /* Safety net */
- assert(session);
-
- /* Clean kernel session teardown */
- teardown_kernel_session(session);
- /* UST session teardown */
- teardown_ust_session(session);
-
- /*
- * Must notify the kernel thread here to update it's poll setin order
- * to remove the channel(s)' fd just destroyed.
- */
- ret = notify_thread_pipe(kernel_poll_pipe[1]);
- if (ret < 0) {
- PERROR("write kernel poll pipe");
- }
-
- ret = session_destroy(session);
-
- return ret;
-}
-
-/*
- * Command LTTNG_CALIBRATE processed by the client thread.
- */
-static int cmd_calibrate(int domain, struct lttng_calibrate *calibrate)
-{
- int ret;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct lttng_kernel_calibrate kcalibrate;
-
- kcalibrate.type = calibrate->type;
- ret = kernel_calibrate(kernel_tracer_fd, &kcalibrate);
- if (ret < 0) {
- ret = LTTCOMM_KERN_ENABLE_FAIL;
- goto error;
- }
- break;
- }
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_ust_calibrate ucalibrate;
-
- ucalibrate.type = calibrate->type;
- ret = ust_app_calibrate_glb(&ucalibrate);
- if (ret < 0) {
- ret = LTTCOMM_UST_CALIBRATE_FAIL;
- goto error;
- }
- break;
- }
- default:
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
- */
-static int cmd_register_consumer(struct ltt_session *session, int domain,
- char *sock_path)
-{
- int ret, sock;
- struct consumer_socket *socket;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* Can't register a consumer if there is already one */
- if (session->kernel_session->consumer_fds_sent != 0) {
- ret = LTTCOMM_KERN_CONSUMER_FAIL;
- goto error;
- }
-
- sock = lttcomm_connect_unix_sock(sock_path);
- if (sock < 0) {
- ret = LTTCOMM_CONNECT_FAIL;
- goto error;
- }
-
- socket = consumer_allocate_socket(sock);
- if (socket == NULL) {
- ret = LTTCOMM_FATAL;
- close(sock);
- goto error;
- }
-
- rcu_read_lock();
- consumer_add_socket(socket, session->kernel_session->consumer);
- rcu_read_unlock();
-
- break;
- default:
- /* TODO: Userspace tracing */
- ret = LTTCOMM_UND;
- goto error;
- }
-
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_LIST_DOMAINS processed by the client thread.
- */
-static ssize_t cmd_list_domains(struct ltt_session *session,
- struct lttng_domain **domains)
-{
- int ret, index = 0;
- ssize_t nb_dom = 0;
-
- if (session->kernel_session != NULL) {
- DBG3("Listing domains found kernel domain");
- nb_dom++;
- }
-
- if (session->ust_session != NULL) {
- DBG3("Listing domains found UST global domain");
- nb_dom++;
- }
-
- *domains = zmalloc(nb_dom * sizeof(struct lttng_domain));
- if (*domains == NULL) {
- ret = -LTTCOMM_FATAL;
- goto error;
- }
-
- if (session->kernel_session != NULL) {
- (*domains)[index].type = LTTNG_DOMAIN_KERNEL;
- index++;
- }
-
- if (session->ust_session != NULL) {
- (*domains)[index].type = LTTNG_DOMAIN_UST;
- index++;
- }
-
- return nb_dom;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_LIST_CHANNELS processed by the client thread.
- */
-static ssize_t cmd_list_channels(int domain, struct ltt_session *session,
- struct lttng_channel **channels)
-{
- int ret;
- ssize_t nb_chan = 0;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- if (session->kernel_session != NULL) {
- nb_chan = session->kernel_session->channel_count;
- }
- DBG3("Number of kernel channels %zd", nb_chan);
- break;
- case LTTNG_DOMAIN_UST:
- if (session->ust_session != NULL) {
- nb_chan = lttng_ht_get_count(
- session->ust_session->domain_global.channels);
- }
- DBG3("Number of UST global channels %zd", nb_chan);
- break;
- default:
- *channels = NULL;
- ret = -LTTCOMM_UND;
- goto error;
- }
-
- if (nb_chan > 0) {
- *channels = zmalloc(nb_chan * sizeof(struct lttng_channel));
- if (*channels == NULL) {
- ret = -LTTCOMM_FATAL;
- goto error;
- }
-
- list_lttng_channels(domain, session, *channels);
- } else {
- *channels = NULL;
- }
-
- return nb_chan;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_LIST_EVENTS processed by the client thread.
- */
-static ssize_t cmd_list_events(int domain, struct ltt_session *session,
- char *channel_name, struct lttng_event **events)
-{
- int ret = 0;
- ssize_t nb_event = 0;
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- if (session->kernel_session != NULL) {
- nb_event = list_lttng_kernel_events(channel_name,
- session->kernel_session, events);
- }
- break;
- case LTTNG_DOMAIN_UST:
- {
- if (session->ust_session != NULL) {
- nb_event = list_lttng_ust_global_events(channel_name,
- &session->ust_session->domain_global, events);
- }
- break;
- }
- default:
- ret = -LTTCOMM_UND;
- goto error;
- }
-
- ret = nb_event;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
- */
-static int cmd_set_consumer_uri(int domain, struct ltt_session *session,
- struct lttng_uri *uri)
-{
- int ret;
- struct ltt_kernel_session *ksess = session->kernel_session;
- struct ltt_ust_session *usess = session->ust_session;
- struct consumer_output *consumer;
-
- /* Can't enable consumer after session started. */
- if (session->enabled) {
- ret = LTTCOMM_TRACE_ALREADY_STARTED;
- goto error;
- }
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- {
- struct lttng_ht_iter iter;
- struct consumer_socket *socket;
-
- /* Code flow error if we don't have a kernel session here. */
- assert(ksess);
-
- /* Create consumer output if none exists */
- consumer = ksess->tmp_consumer;
- if (consumer == NULL) {
- consumer = consumer_copy_output(ksess->consumer);
- if (consumer == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- /* Reassign new pointer */
- ksess->tmp_consumer = consumer;
- }
-
- switch (uri->dtype) {
- case LTTNG_DST_IPV4:
- case LTTNG_DST_IPV6:
- DBG2("Setting network URI for kernel session %s", session->name);
-
- /* Set URI into consumer output object */
- ret = consumer_set_network_uri(consumer, uri);
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- /* On a new subdir, reappend the default trace dir. */
- if (strlen(uri->subdir) != 0) {
- strncat(consumer->subdir, DEFAULT_KERNEL_TRACE_DIR,
- sizeof(consumer->subdir));
- }
-
- cds_lfht_for_each_entry(consumer->socks->ht, &iter.iter,
- socket, node.node) {
- /* Code flow error */
- assert(socket->fd >= 0);
-
- pthread_mutex_lock(socket->lock);
- ret = send_socket_relayd_consumer(domain, session, uri, consumer,
- socket->fd);
- pthread_mutex_unlock(socket->lock);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- }
-
- break;
- case LTTNG_DST_PATH:
- DBG2("Setting trace directory path from URI to %s", uri->dst.path);
- memset(consumer->dst.trace_path, 0,
- sizeof(consumer->dst.trace_path));
- strncpy(consumer->dst.trace_path, uri->dst.path,
- sizeof(consumer->dst.trace_path));
- /* Append default kernel trace dir */
- strncat(consumer->dst.trace_path, DEFAULT_KERNEL_TRACE_DIR,
- sizeof(consumer->dst.trace_path));
- break;
- }
-
- /* All good! */
- break;
- }
- case LTTNG_DOMAIN_UST:
- /* Code flow error if we don't have a kernel session here. */
- assert(usess);
-
- /* Create consumer output if none exists */
- consumer = usess->tmp_consumer;
- if (consumer == NULL) {
- consumer = consumer_copy_output(usess->consumer);
- if (consumer == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- /* Reassign new pointer */
- usess->tmp_consumer = consumer;
- }
-
- switch (uri->dtype) {
- case LTTNG_DST_IPV4:
- case LTTNG_DST_IPV6:
- {
- struct consumer_socket *socket;
-
- DBG2("Setting network URI for UST session %s", session->name);
-
- /* Set URI into consumer object */
- ret = consumer_set_network_uri(consumer, uri);
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- /* On a new subdir, reappend the default trace dir. */
- if (strlen(uri->subdir) != 0) {
- strncat(consumer->subdir, DEFAULT_UST_TRACE_DIR,
- sizeof(consumer->subdir));
- }
-
- rcu_read_lock();
- socket = consumer_find_socket(uatomic_read(&ust_consumerd64_fd),
- consumer);
- if (socket != NULL) {
- pthread_mutex_lock(socket->lock);
- ret = send_socket_relayd_consumer(domain, session, uri,
- consumer, socket->fd);
- pthread_mutex_unlock(socket->lock);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- }
-
- socket = consumer_find_socket(uatomic_read(&ust_consumerd32_fd),
- consumer);
- if (socket != NULL) {
- pthread_mutex_lock(socket->lock);
- ret = send_socket_relayd_consumer(domain, session, uri,
- consumer, socket->fd);
- pthread_mutex_unlock(socket->lock);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- }
- rcu_read_unlock();
- break;
- }
- case LTTNG_DST_PATH:
- DBG2("Setting trace directory path from URI to %s", uri->dst.path);
- memset(consumer->dst.trace_path, 0,
- sizeof(consumer->dst.trace_path));
- strncpy(consumer->dst.trace_path, uri->dst.path,
- sizeof(consumer->dst.trace_path));
- /* Append default UST trace dir */
- strncat(consumer->dst.trace_path, DEFAULT_UST_TRACE_DIR,
- sizeof(consumer->dst.trace_path));
- break;
- }
- break;
- }
-
- /* All good! */
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_DISABLE_CONSUMER processed by the client thread.
- */
-static int cmd_disable_consumer(int domain, struct ltt_session *session)
-{
- int ret;
- struct ltt_kernel_session *ksess = session->kernel_session;
- struct ltt_ust_session *usess = session->ust_session;
- struct consumer_output *consumer;
-
- if (session->enabled) {
- /* Can't disable consumer on an already started session */
- ret = LTTCOMM_TRACE_ALREADY_STARTED;
- goto error;
- }
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* Code flow error if we don't have a kernel session here. */
- assert(ksess);
-
- DBG("Disabling kernel consumer");
- consumer = ksess->consumer;
-
- break;
- case LTTNG_DOMAIN_UST:
- /* Code flow error if we don't have a UST session here. */
- assert(usess);
-
- DBG("Disabling UST consumer");
- consumer = usess->consumer;
-
- break;
- default:
- ret = LTTCOMM_UNKNOWN_DOMAIN;
- goto error;
- }
-
- assert(consumer);
- consumer->enabled = 0;
-
- /* Success at this point */
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Command LTTNG_ENABLE_CONSUMER processed by the client thread.
- */
-static int cmd_enable_consumer(int domain, struct ltt_session *session)
-{
- int ret;
- struct ltt_kernel_session *ksess = session->kernel_session;
- struct ltt_ust_session *usess = session->ust_session;
- struct consumer_output *tmp_out;
-
- /* Can't enable consumer after session started. */
- if (session->enabled) {
- ret = LTTCOMM_TRACE_ALREADY_STARTED;
- goto error;
- }
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* Code flow error if we don't have a kernel session here. */
- assert(ksess);
-
- /*
- * Check if we have already sent fds to the consumer. In that case,
- * the enable-consumer command can't be used because a start trace
- * had previously occured.
- */
- if (ksess->consumer_fds_sent) {
- ret = LTTCOMM_ENABLE_CONSUMER_FAIL;
- goto error;
- }
-
- tmp_out = ksess->tmp_consumer;
- if (tmp_out == NULL) {
- /* No temp. consumer output exists. Using the current one. */
- DBG3("No temporary consumer. Using default");
- ret = LTTCOMM_OK;
- goto error;
- }
-
- switch (tmp_out->type) {
- case CONSUMER_DST_LOCAL:
- DBG2("Consumer output is local. Creating directory(ies)");
-
- /* Create directory(ies) */
- ret = run_as_mkdir_recursive(tmp_out->dst.trace_path,
- S_IRWXU | S_IRWXG, session->uid, session->gid);
- if (ret < 0) {
- if (ret != -EEXIST) {
- ERR("Trace directory creation error");
- ret = LTTCOMM_FATAL;
- goto error;
- }
- }
- break;
- case CONSUMER_DST_NET:
- DBG2("Consumer output is network. Validating URIs");
- /* Validate if we have both control and data path set. */
- if (!tmp_out->dst.net.control_isset) {
- ret = LTTCOMM_URI_CTRL_MISS;
- goto error;
- }
-
- if (!tmp_out->dst.net.data_isset) {
- ret = LTTCOMM_URI_DATA_MISS;
- goto error;
- }
-
- /* Check established network session state */
- if (session->net_handle == 0) {
- ret = LTTCOMM_ENABLE_CONSUMER_FAIL;
- ERR("Session network handle is not set on enable-consumer");
- goto error;
- }
-
- /* Append default kernel trace dir to subdir */
- strncat(ksess->consumer->subdir, DEFAULT_KERNEL_TRACE_DIR,
- sizeof(ksess->consumer->subdir));
-
- break;
- }
-
- /*
- * @session-lock
- * This is race free for now since the session lock is acquired before
- * ending up in this function. No other threads can access this kernel
- * session without this lock hence freeing the consumer output object
- * is valid.
- */
- consumer_destroy_output(ksess->consumer);
- ksess->consumer = tmp_out;
- ksess->tmp_consumer = NULL;
-
- break;
- case LTTNG_DOMAIN_UST:
- /* Code flow error if we don't have a UST session here. */
- assert(usess);
-
- /*
- * Check if we have already sent fds to the consumer. In that case,
- * the enable-consumer command can't be used because a start trace
- * had previously occured.
- */
- if (usess->start_trace) {
- ret = LTTCOMM_ENABLE_CONSUMER_FAIL;
- goto error;
- }
-
- tmp_out = usess->tmp_consumer;
- if (tmp_out == NULL) {
- /* No temp. consumer output exists. Using the current one. */
- DBG3("No temporary consumer. Using default");
- ret = LTTCOMM_OK;
- goto error;
- }
-
- switch (tmp_out->type) {
- case CONSUMER_DST_LOCAL:
- DBG2("Consumer output is local. Creating directory(ies)");
-
- /* Create directory(ies) */
- ret = run_as_mkdir_recursive(tmp_out->dst.trace_path,
- S_IRWXU | S_IRWXG, session->uid, session->gid);
- if (ret < 0) {
- if (ret != -EEXIST) {
- ERR("Trace directory creation error");
- ret = LTTCOMM_FATAL;
- goto error;
- }
- }
- break;
- case CONSUMER_DST_NET:
- DBG2("Consumer output is network. Validating URIs");
- /* Validate if we have both control and data path set. */
- if (!tmp_out->dst.net.control_isset) {
- ret = LTTCOMM_URI_CTRL_MISS;
- goto error;
- }
-
- if (!tmp_out->dst.net.data_isset) {
- ret = LTTCOMM_URI_DATA_MISS;
- goto error;
- }
-
- /* Check established network session state */
- if (session->net_handle == 0) {
- ret = LTTCOMM_ENABLE_CONSUMER_FAIL;
- DBG2("Session network handle is not set on enable-consumer");
- goto error;
- }
-
- if (tmp_out->net_seq_index == -1) {
- ret = LTTCOMM_ENABLE_CONSUMER_FAIL;
- DBG2("Network index is not set on the consumer");
- goto error;
- }
-
- /* Append default kernel trace dir to subdir */
- strncat(usess->consumer->subdir, DEFAULT_UST_TRACE_DIR,
- sizeof(usess->consumer->subdir));
-
- break;
- }
-
- /*
- * @session-lock
- * This is race free for now since the session lock is acquired before
- * ending up in this function. No other threads can access this kernel
- * session without this lock hence freeing the consumer output object
- * is valid.
- */
- consumer_destroy_output(usess->consumer);
- usess->consumer = tmp_out;
- usess->tmp_consumer = NULL;
-
- break;
- }
-
- /* Success at this point */
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-
-/*
- * Process the command requested by the lttng client within the command
- * context structure. This function make sure that the return structure (llm)
- * is set and ready for transmission before returning.
- *
- * Return any error encountered or 0 for success.
- *
- * "sock" is only used for special-case var. len data.
- */
-static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
- int *sock_error)
-{
- int ret = LTTCOMM_OK;
- int need_tracing_session = 1;
- int need_domain;