From: Jérémie Galarneau Date: Wed, 4 Mar 2020 23:27:28 +0000 (-0500) Subject: Fix: lttng: incorrect domain list printed when no domain is provided X-Git-Tag: v2.10.11~4 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7f9bbb9186ad8c7efc7209c44dd1689a338c63dc;p=lttng-tools.git Fix: lttng: incorrect domain list printed when no domain is provided The following commands make use of a common utility function to validate the count of domains specified and print an error when it is invalid: - lttng-enable-event, - lttng-disable-event, - lttng-track, - lttng-untrack, - lttng-add-context, - lttng-enable-channel, - lttng-disable-channel. Those commands do not allow the same domains to be used. In fact, they all expect --kernel or --userspace only, except for the lttng-enable-event, lttng-disable-event, and lttng-add-context commands which allow the --log4j, --jul, and --python domain options to be used. Currently, the error message when no domain is specified is incorrect for all of those commands. The error reads as follows: `Error: Please specify a domain (-k/-u/-j).` For most commands, the -j option cannot be used. For those that allow agent domains, the message is missing the -l and -p domains. This ensures that the expected domains are printed for each of those commands. Moreover, the message is clarified by using the long form option names. Signed-off-by: Jérémie Galarneau Change-Id: I45aee075dbf6c62c4120bdeb06697b88b2d8716c --- diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index d9121b02a..a1b1984b4 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -952,8 +952,8 @@ int cmd_add_context(int argc, const char **argv) goto end; } - ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + - opt_jul + opt_log4j); + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j, true); if (ret) { ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 936884e1f..01327afc0 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -238,7 +238,8 @@ int cmd_disable_channels(int argc, const char **argv) } } - ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace, false); if (ret) { ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 290e72791..c4e0476da 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -378,7 +378,9 @@ 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); + opt_kernel + opt_userspace + opt_jul + opt_log4j + + opt_python, + true); if (ret) { ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 856fea46f..b8c0a5b66 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -647,7 +647,8 @@ int cmd_enable_channels(int argc, const char **argv) } } - ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace, false); if (ret) { ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 1df76e052..ca9395fca 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -1331,7 +1331,9 @@ 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); + opt_kernel + opt_userspace + opt_jul + opt_log4j + + opt_python, + true); if (ret) { ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 3073996a9..c11f46f2f 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -366,7 +366,8 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, } } - ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace, false); if (ret) { command_ret = CMD_ERROR; goto end; diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 52a2440e7..f48ac7453 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -404,15 +404,19 @@ error_socket: return ret; } -int print_missing_or_multiple_domains(unsigned int sum) +int print_missing_or_multiple_domains(unsigned int domain_count, + bool include_agent_domains) { int ret = 0; - if (sum == 0) { - ERR("Please specify a domain (-k/-u/-j)."); + if (domain_count == 0) { + ERR("Please specify a domain (--kernel/--userspace%s).", + include_agent_domains ? + "/--jul/--log4j/--python" : + ""); ret = -1; - } else if (sum > 1) { - ERR("Multiple domains specified."); + } else if (domain_count > 1) { + ERR("Only one domain must be specified."); ret = -1; } diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index 2d20e2bfe..a74359da8 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -55,7 +55,8 @@ int get_count_order_ulong(unsigned long x); const char *get_domain_str(enum lttng_domain_type domain); -int print_missing_or_multiple_domains(unsigned int sum); +int print_missing_or_multiple_domains(unsigned int domain_count, + bool include_agent_domains); int spawn_relayd(const char *pathname, int port); int check_relayd(void);