X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng%2Fcommands%2Fenable_channels.c;h=bd732f22f20d4e4979323c1c75a32f1e0c77dee9;hb=92ab9ab6dd21902978fa091a8b5b789e35176c4b;hp=1bdf60667964ff9d75614dd1e60100b5e8b9537b;hpb=1b57952153a404e726b6d1da1716af3dac671486;p=lttng-tools.git diff --git a/lttng/commands/enable_channels.c b/lttng/commands/enable_channels.c index 1bdf60667..bd732f22f 100644 --- a/lttng/commands/enable_channels.c +++ b/lttng/commands/enable_channels.c @@ -50,6 +50,8 @@ enum { OPT_USERSPACE, }; +static struct lttng_handle *handle; + static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, @@ -96,21 +98,22 @@ static void usage(FILE *ofp) * * Adding channel using the lttng API. */ -static int enable_channel(void) +static int enable_channel(char *session_name) { int ret = CMD_SUCCESS; char *channel_name; struct lttng_domain dom; - if (set_session_name(opt_session_name) < 0) { - ret = CMD_ERROR; - goto error; - } - if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; } + handle = lttng_create_handle(session_name, &dom); + if (handle == NULL) { + ret = -1; + goto error; + } + /* Strip event list */ channel_name = strtok(opt_channels, ","); while (channel_name != NULL) { @@ -122,7 +125,7 @@ static int enable_channel(void) strncpy(chan.name, channel_name, NAME_MAX); chan.name[NAME_MAX - 1] = '\0'; - ret = lttng_enable_channel(&dom, &chan); + ret = lttng_enable_channel(handle, &chan); if (ret < 0) { goto error; } else { @@ -147,6 +150,8 @@ static int enable_channel(void) } error: + lttng_destroy_handle(handle); + return ret; } @@ -157,12 +162,25 @@ error: */ static void init_channel_config(void) { - chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; - chan.attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE; - chan.attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM; - chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; - chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; - chan.attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT; + if (opt_kernel) { + /* kernel default */ + chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; + chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; + chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; + + chan.attr.subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE; + chan.attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM; + chan.attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT; + } else { + /* default behavior, used by UST. */ + chan.attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; + chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; + chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; + + chan.attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE; + chan.attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM; + chan.attr.output = DEFAULT_CHANNEL_OUTPUT; + } } /* @@ -172,6 +190,7 @@ int cmd_enable_channels(int argc, const char **argv) { int opt, ret; static poptContext pc; + char *session_name = NULL; init_channel_config(); @@ -227,7 +246,17 @@ int cmd_enable_channels(int argc, const char **argv) goto end; } - ret = enable_channel(); + if (!opt_session_name) { + session_name = get_session_name(); + if (session_name == NULL) { + ret = -1; + goto end; + } + } else { + session_name = opt_session_name; + } + + ret = enable_channel(session_name); end: return ret;