X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fenable_channels.cpp;h=64317190978882cbc07d0135a695e725dfb1aaf0;hb=5b915816f16e7cb3134dd7279abad79b31c2486c;hp=194ec541eae167077597997fce467e3f10c101bd;hpb=48a4000561343808724f7cb5fa8c131877489ccd;p=lttng-tools.git diff --git a/src/bin/lttng/commands/enable_channels.cpp b/src/bin/lttng/commands/enable_channels.cpp index 194ec541e..643171909 100644 --- a/src/bin/lttng/commands/enable_channels.cpp +++ b/src/bin/lttng/commands/enable_channels.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * * SPDX-License-Identifier: GPL-2.0-only * @@ -16,18 +16,17 @@ #include #include -#include -#include -#include +#include +#include +#include -#include +#include -#include "../command.h" -#include "../utils.h" +#include "../command.hpp" +#include "../utils.hpp" static struct lttng_channel chan_opts; -static char *opt_channels; static int opt_kernel; static char *opt_session_name; static int opt_userspace; @@ -139,7 +138,7 @@ static void set_default_attr(struct lttng_domain *dom) /* * Adding channel using the lttng API. */ -static int enable_channel(char *session_name) +static int enable_channel(char *session_name, char *channel_list) { struct lttng_channel *channel = NULL; int ret = CMD_SUCCESS, warn = 0, error = 0, success = 0; @@ -230,7 +229,7 @@ static int enable_channel(char *session_name) } /* Strip channel list (format: chan1,chan2,...) */ - channel_name = strtok(opt_channels, ","); + channel_name = strtok(channel_list, ","); while (channel_name != NULL) { void *extended_ptr; @@ -391,7 +390,9 @@ int cmd_enable_channels(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + char *channel_list = NULL; char *opt_arg = NULL; + const char *arg_channel_list = NULL; const char *leftover = NULL; init_channel_config(); @@ -644,6 +645,11 @@ int cmd_enable_channels(int argc, const char **argv) ret = CMD_UNDEFINED; goto end; } + + if (opt_arg) { + free(opt_arg); + opt_arg = nullptr; + } } ret = print_missing_or_multiple_domains( @@ -686,9 +692,17 @@ int cmd_enable_channels(int argc, const char **argv) } } - opt_channels = (char*) poptGetArg(pc); - if (opt_channels == NULL) { - ERR("Missing channel name.\n"); + arg_channel_list = poptGetArg(pc); + if (arg_channel_list == NULL) { + ERR("Missing channel name."); + ret = CMD_ERROR; + success = 0; + goto mi_closing; + } + + channel_list = strdup(arg_channel_list); + if (channel_list == NULL) { + PERROR("Failed to copy channel name"); ret = CMD_ERROR; success = 0; goto mi_closing; @@ -713,7 +727,7 @@ int cmd_enable_channels(int argc, const char **argv) session_name = opt_session_name; } - command_ret = enable_channel(session_name); + command_ret = enable_channel(session_name, channel_list); if (command_ret) { success = 0; } @@ -752,8 +766,11 @@ end: free(session_name); } + free(channel_list); + /* Overwrite ret if an error occurred when enable_channel */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); + free(opt_arg); return ret; }