From deaef3cf95d6977530a195ea799fef05171f2292 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/utils.c | 15 +++++++++++++++ src/bin/lttng/utils.h | 6 +----- 8 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index 7211dc5cb..8e0ae83bd 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -567,9 +568,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); @@ -748,6 +747,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 567f4a5fa..86e183884 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -33,7 +33,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 */ @@ -50,6 +50,7 @@ enum { OPT_FUNCTION_ENTRY, OPT_SYSCALL, OPT_USERSPACE, + OPT_KERNEL, OPT_LIST_OPTIONS, }; @@ -59,7 +60,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}, @@ -68,6 +68,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 @@ -132,9 +133,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); @@ -228,6 +228,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; @@ -238,6 +241,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 27f1db5b8..6a5c85521 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -142,9 +142,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); @@ -260,6 +259,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 b50882e04..b75ee7b53 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -179,9 +179,8 @@ static int disable_events(char *session_name) } else if (opt_log4j) { dom.type = LTTNG_DOMAIN_LOG4J; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } channel_name = opt_channel_name; @@ -371,6 +370,13 @@ int cmd_disable_events(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j); + 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 6900dfde8..e63ceb55f 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -219,9 +219,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); @@ -569,6 +568,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 6ebf89f72..2fc24c5cc 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -676,9 +676,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) { @@ -1105,9 +1104,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) { @@ -1388,6 +1385,13 @@ int cmd_enable_events(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j); + 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/utils.c b/src/bin/lttng/utils.c index c271cbc6b..cb58f7604 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -396,3 +396,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 ea92bb9bc..7d383b2e6 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -52,11 +52,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