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>
Mon, 6 Apr 2020 14:35:57 +0000 (10:35 -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 7aef4d50f7dd575e34c704f5b2a82896af8f5db1..82756599f2364ba4719ed8a615f06ba3aa0b3584 100644 (file)
@@ -1115,8 +1115,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 936884e1fc430c79da4ec98b79e24ff8f555fdc3..01327afc0ce29bfc84d520ee94012314c080d6b7 100644 (file)
@@ -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;
index 290e72791e034fb8060ffda8cfd1e8c77ef5e9ea..c4e0476da0acb28478022176e8f427e132206f58 100644 (file)
@@ -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;
index 3a7f9fd06b937141f7493c595ddc16f399233cec..4f04d33d20923f6fabfa9bcdeb2fc372d6842a8c 100644 (file)
@@ -654,7 +654,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 f6bae4874266863e3de6c20350565ad1dc4e0523..e7fd15ab917f2a47ab2cc05cec8b41000bd756ac 100644 (file)
@@ -1782,7 +1782,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 3073996a9f6d19acfa257e87b1075959a9da3521..c11f46f2fd0ee82bb924a0d4fe51296a4f074870 100644 (file)
@@ -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;
index fa2d3c9da626542fc9a0d1bb78bdf017197eedd1..e7df32b934d2432a27b92a780baaa0b3429d809b 100644 (file)
@@ -442,15 +442,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 784e835771dfa1d5de96328f530b667c24581748..35a34e3e11025d3a40bcf3deca3b1eaed72ab299 100644 (file)
@@ -55,7 +55,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.02951 seconds and 4 git commands to generate.