From 66c214cd71e2c8748ff0e1aca0a8238b5c174f06 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 2 Sep 2015 13:33:52 -0400 Subject: [PATCH] Fix: error on no/multiple domain options MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: #927 Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/add_context.c | 12 +++++++++--- src/bin/lttng/commands/calibrate.c | 19 ++++++++++++++----- src/bin/lttng/commands/disable_channels.c | 11 ++++++++--- src/bin/lttng/commands/disable_events.c | 12 +++++++++--- src/bin/lttng/commands/enable_channels.c | 11 ++++++++--- src/bin/lttng/commands/enable_events.c | 16 ++++++++++------ src/bin/lttng/commands/track-untrack.c | 13 ++++++------- src/bin/lttng/utils.c | 15 +++++++++++++++ src/bin/lttng/utils.h | 6 +----- 9 files changed, 80 insertions(+), 35 deletions(-) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index cf3f3efcf..1fce4428c 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -568,9 +569,7 @@ static int add_context(char *session_name) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + assert(0); } handle = lttng_create_handle(session_name, &dom); @@ -749,6 +748,13 @@ int cmd_add_context(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + + if (ret) { + ret = CMD_ERROR; + goto end; + } + if (!opt_type) { ERR("Missing mandatory -t TYPE"); usage(stderr); diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index 80b6d39e7..5a3ebbfaa 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -34,7 +34,7 @@ #include "../command.h" static int opt_event_type; -static char *opt_kernel; +static int opt_kernel; static int opt_userspace; #if 0 /* Not implemented yet */ @@ -51,6 +51,7 @@ enum { OPT_FUNCTION_ENTRY, OPT_SYSCALL, OPT_USERSPACE, + OPT_KERNEL, OPT_LIST_OPTIONS, }; @@ -60,7 +61,6 @@ static struct mi_writer *writer; static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, - {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, #if 0 /* Not implemented yet */ {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, @@ -69,6 +69,7 @@ static struct poptOption long_options[] = { {"marker", 0, POPT_ARG_NONE, 0, OPT_MARKER, 0, 0}, {"probe", 0, POPT_ARG_NONE, 0, OPT_PROBE, 0, 0}, #else + {"kernel", 'k', POPT_ARG_NONE, 0, OPT_KERNEL, 0, 0}, {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, {"function", 0, POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0}, #endif @@ -133,9 +134,8 @@ static int calibrate_lttng(void) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } handle = lttng_create_handle(NULL, &dom); @@ -229,6 +229,9 @@ int cmd_calibrate(int argc, const char **argv) case OPT_USERSPACE: opt_userspace = 1; break; + case OPT_KERNEL: + opt_kernel = 1; + break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; @@ -239,6 +242,12 @@ int cmd_calibrate(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + if (ret) { + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 96a9e5d6c..6bb123fc7 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -143,9 +143,8 @@ static int disable_channels(char *session_name) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } handle = lttng_create_handle(session_name, &dom); @@ -261,6 +260,12 @@ int cmd_disable_channels(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + if (ret) { + ret = CMD_ERROR; + goto end; + } + opt_channels = (char*) poptGetArg(pc); if (opt_channels == NULL) { ERR("Missing channel name(s).\n"); diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 45e91a8bb..7e84f798a 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -185,9 +185,8 @@ static int disable_events(char *session_name) } else if (opt_python) { dom.type = LTTNG_DOMAIN_PYTHON; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } channel_name = opt_channel_name; @@ -377,6 +376,13 @@ int cmd_disable_events(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python); + if (ret) { + ret = CMD_ERROR; + goto end; + } + opt_event_list = (char*) poptGetArg(pc); if (opt_event_list == NULL && opt_disable_all == 0) { ERR("Missing event name(s).\n"); diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 101617fa8..b7863332e 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -220,9 +220,8 @@ static int enable_channel(char *session_name) dom.buf_type = LTTNG_BUFFER_PER_UID; } } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } set_default_attr(&dom); @@ -570,6 +569,12 @@ int cmd_enable_channels(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + if (ret) { + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 68d49769b..972043eeb 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -721,9 +721,8 @@ static int enable_events(char *session_name) /* Default. */ dom.buf_type = LTTNG_BUFFER_PER_UID; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } if (opt_exclude) { @@ -1150,9 +1149,7 @@ static int enable_events(char *session_name) strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + assert(0); } if (!opt_filter) { @@ -1431,6 +1428,13 @@ int cmd_enable_events(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python); + if (ret) { + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index b3139c693..1d84ab927 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -229,9 +230,8 @@ enum cmd_error_code track_untrack_pid(enum cmd_type cmd_type, const char *cmd_st } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto end; + /* Checked by the caller. */ + assert(0); } ret = parse_pid_string(pid_string, all, &pid_list, &nr_pids); @@ -381,10 +381,9 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, } } - if (!(opt_userspace ^ opt_kernel)) { - ERR("Exactly one of -u or -k needs to be specified."); - usage(stderr, cmd_str); - command_ret = CMD_ERROR; + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + if (ret) { + ret = CMD_ERROR; goto end; } diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index d52d4622a..9957b3781 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -401,3 +401,18 @@ error: error_socket: return ret; } + +int print_missing_or_multiple_domains(unsigned int sum) +{ + int ret = 0; + + if (sum == 0) { + ERR("Please specify a domain (-k/-u/-j)."); + ret = -1; + } else if (sum > 1) { + ERR("Multiple domains specified."); + ret = -1; + } + + return ret; +} diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index b0e44f66e..662975a76 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -55,11 +55,7 @@ int get_count_order_ulong(unsigned long x); const char *get_domain_str(enum lttng_domain_type domain); -static inline -void print_missing_domain(void) -{ - ERR("Please specify a domain (-k/-u/-j)."); -} +int print_missing_or_multiple_domains(unsigned int sum); int spawn_relayd(const char *pathname, int port); int check_relayd(void); -- 2.34.1