From: David Goulet Date: Tue, 6 Nov 2012 19:35:43 +0000 (-0500) Subject: Fix: Create default channel on add-context if none X-Git-Tag: v2.1.0-rc7~18 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=979e618e0c03933b16cba3a83285938b25045bdc;p=lttng-tools.git Fix: Create default channel on add-context if none For both kernel and UST, if no channel exists and an add-context command is sent, the default channel0 is created and the context(es) are set. Fixes #391 Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 1404e7f33..46a758e27 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -939,12 +939,23 @@ error: * Command LTTNG_ADD_CONTEXT processed by the client thread. */ int cmd_add_context(struct ltt_session *session, int domain, - char *channel_name, char *event_name, struct lttng_event_context *ctx) + char *channel_name, char *event_name, struct lttng_event_context *ctx, + int kwpipe) { int ret; switch (domain) { case LTTNG_DOMAIN_KERNEL: + assert(session->kernel_session); + + if (session->kernel_session->channel_count == 0) { + /* Create default channel */ + ret = channel_kernel_create(session->kernel_session, NULL, kwpipe); + if (ret != LTTNG_OK) { + goto error; + } + } + /* Add kernel context to kernel tracer */ ret = context_kernel_add(session->kernel_session, ctx, event_name, channel_name); @@ -955,9 +966,28 @@ int cmd_add_context(struct ltt_session *session, int domain, case LTTNG_DOMAIN_UST: { struct ltt_ust_session *usess = session->ust_session; - assert(usess); + unsigned int chan_count = + lttng_ht_get_count(usess->domain_global.channels); + if (chan_count == 0) { + struct lttng_channel *attr; + /* Create default channel */ + attr = channel_new_default_attr(domain); + if (attr == NULL) { + ret = LTTNG_ERR_FATAL; + goto error; + } + + ret = channel_ust_create(usess, domain, attr); + if (ret != LTTNG_OK) { + free(attr); + goto error; + } + free(attr); + } + + ret = context_ust_add(usess, domain, ctx, event_name, channel_name); if (ret != LTTNG_OK) { goto error; diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h index a95cb994e..20fc84a93 100644 --- a/src/bin/lttng-sessiond/cmd.h +++ b/src/bin/lttng-sessiond/cmd.h @@ -45,7 +45,8 @@ int cmd_disable_event(struct ltt_session *session, int domain, int cmd_disable_event_all(struct ltt_session *session, int domain, char *channel_name); int cmd_add_context(struct ltt_session *session, int domain, - char *channel_name, char *event_name, struct lttng_event_context *ctx); + char *channel_name, char *event_name, struct lttng_event_context *ctx, + int kwpipe); int cmd_set_filter(struct ltt_session *session, int domain, char *channel_name, char *event_name, struct lttng_filter_bytecode *bytecode); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 6bc8b00e9..ce2213c1b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2408,7 +2408,7 @@ skip_domain: ret = cmd_add_context(cmd_ctx->session, cmd_ctx->lsm->domain.type, cmd_ctx->lsm->u.context.channel_name, cmd_ctx->lsm->u.context.event_name, - &cmd_ctx->lsm->u.context.ctx); + &cmd_ctx->lsm->u.context.ctx, kernel_poll_pipe[1]); break; } case LTTNG_DISABLE_CHANNEL: