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.
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.
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
.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.
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 */
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);
}
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);
}
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;
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) {
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;
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) {
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);
}
chan_kern_created = 1;
}
-
/* Add kernel context to kernel tracer */
ret = context_kernel_add(session->kernel_session, ctx, channel_name);
if (ret != LTTNG_OK) {
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 */
{
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) {
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);
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) {
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);
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) {
}
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;
/* 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;
};
/*
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) {
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 */
/* 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;
};
/*
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
*
*/
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;
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) {
}
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;
}
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);
}
if (warn) {
ret = CMD_WARNING;
}
- if (opt_channel_name == NULL) {
- free(channel_name);
- }
lttng_destroy_handle(handle);
return ret;
}
}
+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;
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) {
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;
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:
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;
/* 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 */
#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 */
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));
}
}
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;
if (warn) {
ret = CMD_WARNING;
}
- if (opt_channel_name == NULL) {
- free(channel_name);
- }
lttng_destroy_handle(handle);
return ret;
[ 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",
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;
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);
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,
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));
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));
}