Fix: lttng: incorrect domain list printed when no domain is provided
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 4 Mar 2020 23:27:28 +0000 (18:27 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Mar 2020 21:19:53 +0000 (17:19 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I45aee075dbf6c62c4120bdeb06697b88b2d8716c

src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/disable_channels.c
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/track-untrack.c
src/bin/lttng/utils.c
src/bin/lttng/utils.h

index 994cd49eb32037b898dc3fcac9853c3681ebd9a9..de54721cb5a2c3571a02cf93163d6c99b8e83490 100644 (file)
@@ -1147,8 +1147,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;
index 7aba82c02d8b63ff9b66f835538faa9f2ecada76..344be237d26c2d4581c26c50363dbbe7558293ff 100644 (file)
@@ -228,7 +228,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;
index 501c3cf3aa7bc31caecf8792a68a5966c4086594..a42c3a3cd52849c044d9a61a7304113b0db7a56c 100644 (file)
@@ -368,7 +368,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;
index 59fde7d4cec50c7c2486c6951d7edae157024030..fa65b1eaa9257d84e3be698a7e10a9960683c0d8 100644 (file)
@@ -644,7 +644,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;
index 0de6a0cd4e42d42d9d058a8c12c6cfa66e5b6c8c..f41dc9ecac7424e0a4edc458a982f00353646c95 100644 (file)
@@ -1772,7 +1772,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;
index c674faefa625d98292522151956c6870d14b57c0..498e7ed31e938cb5fbc7d0a39b4f6528f2418d46 100644 (file)
@@ -670,7 +670,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;
index e88166a438a06f98177d7a722ce5561b111b0617..61718e54d2414ace10097f5d3b558fddc086a4ad 100644 (file)
@@ -432,15 +432,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;
        }
 
index fe82364a04c284f03650bf8ab9e467c05c7f6333..cc7d7afcac7f5b2412be9eafc74448422fe95ef8 100644 (file)
@@ -45,7 +45,8 @@ int get_count_order_ulong(unsigned long x);
 const char *get_domain_str(enum lttng_domain_type domain);
 const char *get_event_type_str(enum lttng_event_type event_type);
 
-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);
This page took 0.030965 seconds and 4 git commands to generate.