X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng-sessiond%2Fmain.c;h=4bb7240378161540cb4573e4a3fc91e076dbdbae;hp=dc71e0eaea851990e8982f7152f5bd043733cdaa;hb=596219f7620add67e61a4666e7b5f4b1e79ade1a;hpb=8f7a84dd224c529cb7a366f6b191d57bf980d339 diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index dc71e0eae..4bb724037 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -1922,6 +1922,7 @@ static void list_lttng_channels(int domain, struct ltt_session *session, channels[i].attr.read_timer_interval = uchan->attr.read_timer_interval; channels[i].attr.output = uchan->attr.output; + channels[i].enabled = uchan->enabled; i++; } break; @@ -2072,22 +2073,52 @@ 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; - } + 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; + kernel_wait_quiescent(kernel_tracer_fd); + break; + } + case LTTNG_DOMAIN_UST: + { + struct ltt_ust_channel *uchan; + + /* Get channel in global UST domain HT */ + 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 = ust_app_disable_channel_all(usess, uchan); + if (ret < 0) { + ret = LTTCOMM_UST_DISABLE_FAIL; + goto error; + } + + uchan->enabled = 0; + + break; + } + case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: + case LTTNG_DOMAIN_UST_EXEC_NAME: + case LTTNG_DOMAIN_UST_PID: + ret = LTTCOMM_NOT_IMPLEMENTED; + goto error; + default: + ret = LTTCOMM_UNKNOWN_DOMAIN; + goto error; } ret = LTTCOMM_OK; @@ -2134,14 +2165,14 @@ error: * 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 domain, struct lttng_channel *attr) { int ret; struct ltt_ust_session *usess = session->ust_session; DBG("Enabling channel %s for session %s", attr->name, session->name); - switch (domain->type) { + switch (domain) { case LTTNG_DOMAIN_KERNEL: { struct ltt_kernel_channel *kchan; @@ -2182,65 +2213,36 @@ static int cmd_enable_channel(struct ltt_session *session, hashtable_add_unique(usess->domain_global.channels, &uchan->node); rcu_read_unlock(); DBG2("UST channel %s added to global domain HT", attr->name); + + /* Add channel to all registered applications */ + ret = ust_app_create_channel_all(usess, uchan); + if (ret != 0) { + ret = LTTCOMM_UST_CHAN_FAIL; + goto error; + } } else { - ret = LTTCOMM_UST_CHAN_EXIST; - goto error; - } + /* If already enabled, everything is OK */ + if (uchan->enabled) { + ret = LTTCOMM_OK; + goto error; + } - /* Add channel to all registered applications */ - ret = ust_app_create_channel_all(usess, uchan); - if (ret != 0) { - goto error; + ret = ust_app_enable_channel_all(usess, uchan); + if (ret < 0) { + ret = LTTCOMM_UST_ENABLE_FAIL; + goto error; + } } uchan->enabled = 1; break; } + case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: + case LTTNG_DOMAIN_UST_EXEC_NAME: 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; - - uchan = trace_ust_get_channel_by_name(attr->name, usess); - if (uchan == NULL) { - ret = channel_ust_create(usess, attr, sock); - } else { - ret = channel_ust_enable(usess, uchan, sock); - } - - if (ret != LTTCOMM_OK) { - goto error; - } - - ret = copy_ust_channel_to_app(usess, attr, app); - if (ret != LTTCOMM_OK) { - goto error; - } - - DBG("UST channel %s created for app sock %d with pid %d", - attr->name, app->sock, domain->attr.pid); - */ ret = LTTCOMM_NOT_IMPLEMENTED; goto error; - } default: ret = LTTCOMM_UNKNOWN_DOMAIN; goto error; @@ -2432,13 +2434,35 @@ static int cmd_enable_event(struct ltt_session *session, int domain, { struct ltt_ust_channel *uchan; struct ltt_ust_event *uevent; + struct lttng_channel *attr; uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, channel_name); if (uchan == NULL) { - /* TODO: Create default channel */ - ret = LTTCOMM_UST_CHAN_NOT_FOUND; - goto error; + /* 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); + + /* Use the internal command enable channel */ + ret = cmd_enable_channel(session, domain, attr); + if (ret < 0) { + 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; + } } uevent = trace_ust_find_event_by_name(uchan->events, event->name); @@ -2720,7 +2744,6 @@ static int cmd_stop_trace(struct ltt_session *session) kernel_wait_quiescent(kernel_tracer_fd); } - /* Flag session that trace should start automatically */ if (usess) { usess->start_trace = 0; @@ -3159,7 +3182,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx) } case LTTNG_ENABLE_CHANNEL: { - ret = cmd_enable_channel(cmd_ctx->session, &cmd_ctx->lsm->domain, + ret = cmd_enable_channel(cmd_ctx->session, cmd_ctx->lsm->domain.type, &cmd_ctx->lsm->u.channel.chan); break; }