Fix: Create default channel on add-context if none
authorDavid Goulet <dgoulet@efficios.com>
Tue, 6 Nov 2012 19:35:43 +0000 (14:35 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 6 Nov 2012 19:35:46 +0000 (14:35 -0500)
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 <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/cmd.h
src/bin/lttng-sessiond/main.c

index 1404e7f33f68d0e5ecec0f1d9544f330c7493526..46a758e27eab8f9b01c502256bde42a60b32702d 100644 (file)
@@ -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;
index a95cb994e7104846a99deb2fc500200eb4e1f017..20fc84a9300ffe7680fb7aa9f0d48d1b28b07a26 100644 (file)
@@ -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);
index 6bc8b00e914b1d1d6a15c6e82d2e0f520609afcc..ce2213c1bd2897e46df7b38f822e9e3cb061a20e 100644 (file)
@@ -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:
This page took 0.041883 seconds and 4 git commands to generate.