Fix: (slight UI change) refuse missing -c if non-default channel exists
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 19 Jul 2013 13:04:29 +0000 (09:04 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 19 Jul 2013 13:11:13 +0000 (09:11 -0400)
After a user creates a channel within a session, creating a "default"
channel if a user forgets to put "-c channel_name" in the following
add-context, enable-event, disable-event commands is misleading.  The
natural expected behavior would be that the command would apply the the
last enabled channel (notion of a "current" channel, like we have for
sessions), but certainly not that it creates a new channel with default
attributes behind the user's back.

An intermediate fix that would not require to keep a notion of current
channel is to refuse creation of a default channel if at least one
non-default channel has already been created in the session.

This commit affects enable-event, disable-event and add-context
commands.

This fix belongs to the 2.3-rc cycle, and cannot be backported, since
it:

a) changes the user interface of lttng (returns an error in the case
   where -c name is missing and the session contains an non-default
   channel)
b) changes the ABI between lttng-ctl and sessiond: a default channel is
   now expressed as an empty string ('\0') rather than by "channel0",
   which allows making the difference between an explicit "channel0"
   channel and a default channel in the session daemon.

Fixes #522

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
doc/man/lttng.1
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/trace-kernel.c
src/bin/lttng-sessiond/trace-kernel.h
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_events.c
src/common/error.c
src/common/ust-consumer/ust-consumer.c
src/lib/lttng-ctl/lttng-ctl.c

index 236603fa087eaa3dbe5432f867653f7c2acef816..c0df4311948a80997d072f67caad81543875917c 100644 (file)
@@ -104,7 +104,9 @@ contexts.
 
 If no channel is given (\-c), the context is added to all channels that were
 already enabled. If the session has no channel, a default channel is created.
-Otherwise the context will be added only to the given channel (\-c).
+If \fB\-c, \-\-channel\fP is omitted, but a non-default channel already
+exists within the session, an error is returned.  Otherwise the context
+will be added only to the given channel (\-c).
 
 If \fB\-s, \-\-session\fP is omitted, the session name is taken from the .lttngrc
 file.
@@ -453,8 +455,10 @@ Enable tracing event
 
 A tracing event is always assigned to a channel. If \fB\-c, \-\-channel\fP is
 omitted, a default channel named '\fBchannel0\fP' is created and the event is
-added to it. For the user-space tracer, using \fB\-a, \-\-all\fP is the same as
-using the wildcard "*".
+added to it. If \fB\-c, \-\-channel\fP is omitted, but a non-default
+channel already exists within the session, an error is returned. For the
+user-space tracer, using \fB\-a, \-\-all\fP is the same as using the
+wildcard "*".
 
 If \fB\-s, \-\-session\fP is omitted, the session name is taken from the .lttngrc
 file.
@@ -595,6 +599,10 @@ NAME\fP again.
 If \fB\-s, \-\-session\fP is omitted, the session name is taken from the .lttngrc
 file.
 
+If \fB\-c, \-\-channel\fP is omitted, the default channel name is used.
+If \fB\-c, \-\-channel\fP is omitted, but a non-default channel already
+exists within the session, an error is returned.
+
 .B OPTIONS:
 
 .TP
@@ -607,6 +615,9 @@ Simple listing of options
 .BR "\-s, \-\-session NAME"
 Apply on session name
 .TP
+.BR "\-c, \-\-channel NAME"
+Apply on channel name
+.TP
 .BR "\-a, \-\-all-events"
 Disable all events. This does NOT disable "*" but rather every known
 events of the session.
index 4e98f43bea86eca94969a4b1de859ebf01a12f00..51ef9ca1ed52773b9e766acafafdf7e061ad422c 100644 (file)
@@ -113,7 +113,7 @@ enum lttng_error_code {
        LTTNG_ERR_TRACE_ALREADY_STARTED  = 80,  /* Tracing already started */
        LTTNG_ERR_TRACE_ALREADY_STOPPED  = 81,  /* Tracing already stopped */
        LTTNG_ERR_KERN_EVENT_ENOSYS      = 82,  /* Kernel event type not supported */
-       /* 83 */
+       LTTNG_ERR_NEED_CHANNEL_NAME      = 83,  /* Non-default channel exists within session: channel name needs to be specified with '-c name' */
        /* 84 */
        /* 85 */
        /* 86 */
index a351d63de706b8843c7b16059f45ba2173b91e6c..84594ad24927bf9ab4771d534f4dc8f88360491e 100644 (file)
@@ -877,6 +877,9 @@ int cmd_enable_channel(struct ltt_session *session,
                                session->kernel_session);
                if (kchan == NULL) {
                        ret = channel_kernel_create(session->kernel_session, attr, wpipe);
+                       if (attr->name[0] != '\0') {
+                               session->kernel_session->has_non_default_channel = 1;
+                       }
                } else {
                        ret = channel_kernel_enable(session->kernel_session, kchan);
                }
@@ -897,6 +900,9 @@ int cmd_enable_channel(struct ltt_session *session,
                uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
                if (uchan == NULL) {
                        ret = channel_ust_create(usess, attr, domain->buf_type);
+                       if (attr->name[0] != '\0') {
+                               usess->has_non_default_channel = 1;
+                       }
                } else {
                        ret = channel_ust_enable(usess, uchan);
                }
@@ -931,6 +937,16 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 
                ksess = session->kernel_session;
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (ksess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
                if (kchan == NULL) {
                        ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
@@ -952,6 +968,16 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 
                usess = session->ust_session;
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (usess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
@@ -1003,6 +1029,16 @@ int cmd_disable_event_all(struct ltt_session *session, int domain,
 
                ksess = session->kernel_session;
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (ksess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
                if (kchan == NULL) {
                        ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
@@ -1024,6 +1060,16 @@ int cmd_disable_event_all(struct ltt_session *session, int domain,
 
                usess = session->ust_session;
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (usess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
@@ -1069,6 +1115,17 @@ int cmd_add_context(struct ltt_session *session, int domain,
        case LTTNG_DOMAIN_KERNEL:
                assert(session->kernel_session);
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (session->kernel_session->has_non_default_channel
+                               && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                if (session->kernel_session->channel_count == 0) {
                        /* Create default channel */
                        ret = channel_kernel_create(session->kernel_session, NULL, kwpipe);
@@ -1077,7 +1134,6 @@ int cmd_add_context(struct ltt_session *session, int domain,
                        }
                        chan_kern_created = 1;
                }
-
                /* Add kernel context to kernel tracer */
                ret = context_kernel_add(session->kernel_session, ctx, channel_name);
                if (ret != LTTNG_OK) {
@@ -1087,10 +1143,21 @@ int cmd_add_context(struct ltt_session *session, int domain,
        case LTTNG_DOMAIN_UST:
        {
                struct ltt_ust_session *usess = session->ust_session;
+               unsigned int chan_count;
+
                assert(usess);
 
-               unsigned int chan_count =
-                       lttng_ht_get_count(usess->domain_global.channels);
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (usess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
+               chan_count = lttng_ht_get_count(usess->domain_global.channels);
                if (chan_count == 0) {
                        struct lttng_channel *attr;
                        /* Create default channel */
@@ -1173,6 +1240,17 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
        {
                struct ltt_kernel_channel *kchan;
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (session->kernel_session->has_non_default_channel
+                               && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                kchan = trace_kernel_get_channel_by_name(channel_name,
                                session->kernel_session);
                if (kchan == NULL) {
@@ -1222,6 +1300,16 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
 
                assert(usess);
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (usess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                /* Get channel from global UST domain */
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
@@ -1294,6 +1382,17 @@ int cmd_enable_event_all(struct ltt_session *session,
 
                assert(session->kernel_session);
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (session->kernel_session->has_non_default_channel
+                               && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                kchan = trace_kernel_get_channel_by_name(channel_name,
                                session->kernel_session);
                if (kchan == NULL) {
@@ -1358,6 +1457,16 @@ int cmd_enable_event_all(struct ltt_session *session,
 
                assert(usess);
 
+               /*
+                * If a non-default channel has been created in the
+                * session, explicitely require that -c chan_name needs
+                * to be provided.
+                */
+               if (usess->has_non_default_channel && channel_name[0] == '\0') {
+                       ret = LTTNG_ERR_NEED_CHANNEL_NAME;
+                       goto error;
+               }
+
                /* Get channel from global UST domain */
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
index 33e5488ef293fde00f2841094f17d92e15e0a834..0c14052e1a37aeb986ab51ab14e6578caa3d0ad9 100644 (file)
@@ -38,6 +38,13 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
        assert(session);
        assert(name);
 
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (name[0] == '\0')
+               name = DEFAULT_CHANNEL_NAME;
+
        DBG("Trying to find channel %s", name);
 
        cds_list_for_each_entry(chan, &session->channel_list.head, list) {
@@ -144,6 +151,16 @@ struct ltt_kernel_channel *trace_kernel_create_channel(
        }
        memcpy(lkc->channel, chan, sizeof(struct lttng_channel));
 
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (chan->name[0] == '\0') {
+               strncpy(lkc->channel->name, DEFAULT_CHANNEL_NAME,
+                       sizeof(lkc->channel->name));
+       }
+       lkc->channel->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+
        lkc->fd = -1;
        lkc->stream_count = 0;
        lkc->event_count = 0;
index 5502e42bdb4d8304186779eae182548a10574537..934aaffe89f5174015a3fe4d9637eeeabbd818bc 100644 (file)
@@ -114,6 +114,7 @@ struct ltt_kernel_session {
        /* Tell or not if the session has to output the traces. */
        unsigned int output_traces;
        unsigned int snapshot_mode;
+       unsigned int has_non_default_channel;
 };
 
 /*
index 9eabf6225376360d2eef8e9d83d33b668e84c35e..c80d5e772de8c48e913b5399f23be7af785241c5 100644 (file)
@@ -128,6 +128,13 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
        struct lttng_ht_node_str *node;
        struct lttng_ht_iter iter;
 
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (name[0] == '\0')
+               name = DEFAULT_CHANNEL_NAME;
+
        lttng_ht_lookup(ht, (void *)name, &iter);
        node = lttng_ht_iter_get_node_str(&iter);
        if (node == NULL) {
@@ -268,8 +275,16 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
                break;
        }
 
-       /* Copy channel name */
-       strncpy(luc->name, chan->name, sizeof(luc->name));
+       /*
+        * If we receive an empty string for channel name, it means the
+        * default channel name is requested.
+        */
+       if (chan->name[0] == '\0') {
+               strncpy(luc->name, DEFAULT_CHANNEL_NAME, sizeof(luc->name));
+       } else {
+               /* Copy channel name */
+               strncpy(luc->name, chan->name, sizeof(luc->name));
+       }
        luc->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
 
        /* Init node */
index 5ca7964ea40c074e853e4a49cd7c28f37a28cab4..f4244fdefae8196a2dadfc092e844dc90a626f05 100644 (file)
@@ -108,6 +108,7 @@ struct ltt_ust_session {
        /* Tell or not if the session has to output the traces. */
        unsigned int output_traces;
        unsigned int snapshot_mode;
+       unsigned int has_non_default_channel;
 };
 
 /*
index ac3d4a4730405d3ed00980697c3ea6b99568e74f..f9dc3396bf1377ae7caadd10bf780cb3e612a6fc 100644 (file)
@@ -82,6 +82,18 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
 }
 
+static
+const char *print_channel_name(const char *name)
+{
+       return name ? : DEFAULT_CHANNEL_NAME;
+}
+
+static
+const char *print_raw_channel_name(const char *name)
+{
+       return name ? : "<default>";
+}
+
 /*
  *  disable_events
  *
@@ -89,7 +101,7 @@ static void usage(FILE *ofp)
  */
 static int disable_events(char *session_name)
 {
-       int err, ret = CMD_SUCCESS, warn = 0;
+       int ret = CMD_SUCCESS, warn = 0;
        char *event_name, *channel_name = NULL;
        struct lttng_domain dom;
 
@@ -106,16 +118,7 @@ static int disable_events(char *session_name)
                goto error;
        }
 
-       /* Get channel name */
-       if (opt_channel_name == NULL) {
-               err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
-               if (err < 0) {
-                       ret = CMD_FATAL;
-                       goto error;
-               }
-       } else {
-               channel_name = opt_channel_name;
-       }
+       channel_name = opt_channel_name;
 
        handle = lttng_create_handle(session_name, &dom);
        if (handle == NULL) {
@@ -131,7 +134,8 @@ static int disable_events(char *session_name)
                }
 
                MSG("All %s events are disabled in channel %s",
-                               opt_kernel ? "kernel" : "UST", channel_name);
+                               opt_kernel ? "kernel" : "UST",
+                               print_channel_name(channel_name));
                goto end;
        }
 
@@ -143,11 +147,16 @@ static int disable_events(char *session_name)
                ret = lttng_disable_event(handle, event_name, channel_name);
                if (ret < 0) {
                        ERR("Event %s: %s (channel %s, session %s)", event_name,
-                                       lttng_strerror(ret), channel_name, session_name);
+                                       lttng_strerror(ret),
+                                       ret == -LTTNG_ERR_NEED_CHANNEL_NAME
+                                               ? print_raw_channel_name(channel_name)
+                                               : print_channel_name(channel_name),
+                                       session_name);
                        warn = 1;
                } else {
                        MSG("%s event %s disabled in channel %s for session %s",
-                                       opt_kernel ? "kernel" : "UST", event_name, channel_name,
+                                       opt_kernel ? "kernel" : "UST", event_name,
+                                       print_channel_name(channel_name),
                                        session_name);
                }
 
@@ -162,9 +171,6 @@ error:
        if (warn) {
                ret = CMD_WARNING;
        }
-       if (opt_channel_name == NULL) {
-               free(channel_name);
-       }
        lttng_destroy_handle(handle);
 
        return ret;
index 18a958d321e6101d1de0c2c6ff00f75fae9e06bd..26195af5a7582cd7c6afccda6a1d3827d6d1bd07 100644 (file)
@@ -312,12 +312,24 @@ int loglevel_str_to_value(const char *inputstr)
        }
 }
 
+static
+const char *print_channel_name(const char *name)
+{
+       return name ? : DEFAULT_CHANNEL_NAME;
+}
+
+static
+const char *print_raw_channel_name(const char *name)
+{
+       return name ? : "<default>";
+}
+
 /*
  * Enabling event using the lttng API.
  */
 static int enable_events(char *session_name)
 {
-       int err, ret = CMD_SUCCESS, warn = 0;
+       int ret = CMD_SUCCESS, warn = 0;
        char *event_name, *channel_name = NULL;
        struct lttng_event ev;
        struct lttng_domain dom;
@@ -347,15 +359,7 @@ static int enable_events(char *session_name)
                goto error;
        }
 
-       if (opt_channel_name == NULL) {
-               err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
-               if (err < 0) {
-                       ret = CMD_FATAL;
-                       goto error;
-               }
-       } else {
-               channel_name = opt_channel_name;
-       }
+       channel_name = opt_channel_name;
 
        handle = lttng_create_handle(session_name, &dom);
        if (handle == NULL) {
@@ -392,11 +396,15 @@ static int enable_events(char *session_name)
                                switch (-ret) {
                                case LTTNG_ERR_KERN_EVENT_EXIST:
                                        WARN("Kernel events already enabled (channel %s, session %s)",
-                                                       channel_name, session_name);
+                                                       print_channel_name(channel_name), session_name);
                                        break;
                                default:
                                        ERR("Events: %s (channel %s, session %s)",
-                                                       lttng_strerror(ret), channel_name, session_name);
+                                                       lttng_strerror(ret),
+                                                       ret == -LTTNG_ERR_NEED_CHANNEL_NAME
+                                                               ? print_raw_channel_name(channel_name)
+                                                               : print_channel_name(channel_name),
+                                                       session_name);
                                        break;
                                }
                                goto end;
@@ -406,28 +414,32 @@ static int enable_events(char *session_name)
                        case LTTNG_EVENT_TRACEPOINT:
                                if (opt_loglevel) {
                                        MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
-                                                       opt_kernel ? "kernel" : "UST", channel_name,
+                                                       opt_kernel ? "kernel" : "UST",
+                                                       print_channel_name(channel_name),
                                                        opt_loglevel);
                                } else {
                                        MSG("All %s tracepoints are enabled in channel %s",
-                                                       opt_kernel ? "kernel" : "UST", channel_name);
+                                                       opt_kernel ? "kernel" : "UST",
+                                                       print_channel_name(channel_name));
 
                                }
                                break;
                        case LTTNG_EVENT_SYSCALL:
                                if (opt_kernel) {
                                        MSG("All kernel system calls are enabled in channel %s",
-                                                       channel_name);
+                                                       print_channel_name(channel_name));
                                }
                                break;
                        case LTTNG_EVENT_ALL:
                                if (opt_loglevel) {
                                        MSG("All %s events are enabled in channel %s for loglevel %s",
-                                                       opt_kernel ? "kernel" : "UST", channel_name,
+                                                       opt_kernel ? "kernel" : "UST",
+                                                       print_channel_name(channel_name),
                                                        opt_loglevel);
                                } else {
                                        MSG("All %s events are enabled in channel %s",
-                                                       opt_kernel ? "kernel" : "UST", channel_name);
+                                                       opt_kernel ? "kernel" : "UST",
+                                                       print_channel_name(channel_name));
                                }
                                break;
                        default:
@@ -444,14 +456,17 @@ static int enable_events(char *session_name)
                        if (ret < 0) {
                                switch (-ret) {
                                case LTTNG_ERR_FILTER_EXIST:
-                                       WARN("Filter on events is already enabled"
+                                       WARN("Filter on all events is already enabled"
                                                        " (channel %s, session %s)",
-                                               channel_name, session_name);
+                                               print_channel_name(channel_name), session_name);
                                        break;
-                               case LTTNG_ERR_FILTER_INVAL:
-                               case LTTNG_ERR_FILTER_NOMEM:
                                default:
-                                       ERR("%s", lttng_strerror(ret));
+                                       ERR("All events: %s (channel %s, session %s, filter \'%s\')",
+                                                       lttng_strerror(ret),
+                                                       ret == -LTTNG_ERR_NEED_CHANNEL_NAME
+                                                               ? print_raw_channel_name(channel_name)
+                                                               : print_channel_name(channel_name),
+                                                       session_name, opt_filter);
                                        break;
                                }
                                goto error;
@@ -473,7 +488,8 @@ static int enable_events(char *session_name)
                /* Kernel tracer action */
                if (opt_kernel) {
                        DBG("Enabling kernel event %s for channel %s",
-                                       event_name, channel_name);
+                                       event_name,
+                                       print_channel_name(channel_name));
 
                        switch (opt_event_type) {
                        case LTTNG_EVENT_ALL:   /* Default behavior is tracepoint */
@@ -528,7 +544,7 @@ static int enable_events(char *session_name)
 #endif
 
                        DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
-                                       channel_name, opt_loglevel ? : "<all>");
+                                       print_channel_name(channel_name), opt_loglevel ? : "<all>");
 
                        switch (opt_event_type) {
                        case LTTNG_EVENT_ALL:   /* Default behavior is tracepoint */
@@ -573,17 +589,23 @@ static int enable_events(char *session_name)
                                switch (-ret) {
                                case LTTNG_ERR_KERN_EVENT_EXIST:
                                        WARN("Kernel event %s already enabled (channel %s, session %s)",
-                                                       event_name, channel_name, session_name);
+                                                       event_name,
+                                                       print_channel_name(channel_name), session_name);
                                        break;
                                default:
                                        ERR("Event %s: %s (channel %s, session %s)", event_name,
-                                                       lttng_strerror(ret), channel_name, session_name);
+                                                       lttng_strerror(ret),
+                                                       ret == -LTTNG_ERR_NEED_CHANNEL_NAME
+                                                               ? print_raw_channel_name(channel_name)
+                                                               : print_channel_name(channel_name),
+                                                       session_name);
                                        break;
                                }
                                warn = 1;
                        } else {
                                MSG("%s event %s created in channel %s",
-                                               opt_kernel ? "kernel": "UST", event_name, channel_name);
+                                               opt_kernel ? "kernel": "UST", event_name,
+                                               print_channel_name(channel_name));
                        }
                }
 
@@ -595,14 +617,16 @@ static int enable_events(char *session_name)
                                case LTTNG_ERR_FILTER_EXIST:
                                        WARN("Filter on event %s is already enabled"
                                                        " (channel %s, session %s)",
-                                               event_name, channel_name, session_name);
+                                               event_name,
+                                               print_channel_name(channel_name), session_name);
                                        break;
-                               case LTTNG_ERR_FILTER_INVAL:
-                               case LTTNG_ERR_FILTER_NOMEM:
-                                       ERR("%s", lttng_strerror(ret));
                                default:
-                                       ERR("Setting filter for event %s: '%s'", ev.name,
-                                                       opt_filter);
+                                       ERR("Event %s: %s (channel %s, session %s, filter \'%s\')", ev.name,
+                                                       lttng_strerror(ret),
+                                                       ret == -LTTNG_ERR_NEED_CHANNEL_NAME
+                                                               ? print_raw_channel_name(channel_name)
+                                                               : print_channel_name(channel_name),
+                                                       session_name, opt_filter);
                                        break;
                                }
                                goto error;
@@ -620,9 +644,6 @@ error:
        if (warn) {
                ret = CMD_WARNING;
        }
-       if (opt_channel_name == NULL) {
-               free(channel_name);
-       }
        lttng_destroy_handle(handle);
 
        return ret;
index 5851012529902f176d3d2c39d6fa0ac8de765551..acfd6c678b7b2ce0add7aeed8f47f41fc631955c 100644 (file)
@@ -86,6 +86,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_TRACE_ALREADY_STARTED) ] = "Tracing already started",
        [ ERROR_INDEX(LTTNG_ERR_TRACE_ALREADY_STOPPED) ] = "Tracing already stopped",
        [ ERROR_INDEX(LTTNG_ERR_KERN_EVENT_ENOSYS) ] = "Kernel event type not supported",
+       [ ERROR_INDEX(LTTNG_ERR_NEED_CHANNEL_NAME) ] = "Non-default channel exists within session: channel name needs to be specified with '-c name'",
        [ ERROR_INDEX(LTTNG_ERR_INVALID) ] = "Invalid parameter",
        [ ERROR_INDEX(LTTNG_ERR_NO_USTCONSUMERD) ] = "No UST consumer detected",
        [ ERROR_INDEX(LTTNG_ERR_NO_KERNCONSUMERD) ] = "No kernel consumer detected",
index f8c02ee72cf03adf6eeca28548aa4f0aff98afcb..4f374f030a9ed1f061a021b8836c4c1c250488ff 100644 (file)
@@ -1568,6 +1568,8 @@ int lttng_ustconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
        DBG("In UST read_subbuffer (wait_fd: %d, name: %s)", stream->wait_fd,
                        stream->name);
 
+       sleep(1);
+
        /* Ease our life for what's next. */
        ustream = stream->ustream;
 
index d8d5db6c7ff6838d087309c421c83cb919e0758c..033a28105ef6744f464434c32ad0f01b2ada889c 100644 (file)
@@ -640,9 +640,14 @@ int lttng_add_context(struct lttng_handle *handle,
 
        lsm.cmd_type = LTTNG_ADD_CONTEXT;
 
-       /* Copy channel name */
-       lttng_ctl_copy_string(lsm.u.context.channel_name, channel_name,
-                       sizeof(lsm.u.context.channel_name));
+       /* If no channel name, send empty string. */
+       if (channel_name == NULL) {
+               lttng_ctl_copy_string(lsm.u.context.channel_name, "",
+                               sizeof(lsm.u.context.channel_name));
+       } else {
+               lttng_ctl_copy_string(lsm.u.context.channel_name, channel_name,
+                               sizeof(lsm.u.context.channel_name));
+       }
 
        lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
 
@@ -671,9 +676,9 @@ int lttng_enable_event(struct lttng_handle *handle,
 
        memset(&lsm, 0, sizeof(lsm));
 
-       /* If no channel name, we put the default name */
+       /* If no channel name, send empty string. */
        if (channel_name == NULL) {
-               lttng_ctl_copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
+               lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
                                sizeof(lsm.u.enable.channel_name));
        } else {
                lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
@@ -800,9 +805,15 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle,
 
        lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_FILTER;
 
-       /* Copy channel name */
-       lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
-                       sizeof(lsm.u.enable.channel_name));
+       /* If no channel name, send empty string. */
+       if (channel_name == NULL) {
+               lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
+                               sizeof(lsm.u.enable.channel_name));
+       } else {
+               lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
+                               sizeof(lsm.u.enable.channel_name));
+       }
+
        /* Copy event name */
        if (event) {
                memcpy(&lsm.u.enable.event, event, sizeof(lsm.u.enable.event));
@@ -855,11 +866,12 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name,
 
        memset(&lsm, 0, sizeof(lsm));
 
-       if (channel_name) {
-               lttng_ctl_copy_string(lsm.u.disable.channel_name, channel_name,
+       /* If no channel name, send empty string. */
+       if (channel_name == NULL) {
+               lttng_ctl_copy_string(lsm.u.disable.channel_name, "",
                                sizeof(lsm.u.disable.channel_name));
        } else {
-               lttng_ctl_copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME,
+               lttng_ctl_copy_string(lsm.u.disable.channel_name, channel_name,
                                sizeof(lsm.u.disable.channel_name));
        }
 
This page took 0.056664 seconds and 4 git commands to generate.