Fix: error on no/multiple domain options
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 2 Sep 2015 17:33:52 +0000 (13:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Sep 2015 00:53:54 +0000 (20:53 -0400)
Fixes: #927
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/calibrate.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 cf3f3efcf36f87464e5c5eb05425e6bcfccbbd8e..1fce4428c8377b95624a8531cd5106d6b8a0f8be 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <urcu/list.h>
 
@@ -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);
index 80b6d39e7469b87ebdcf0a8dcd934d6af089ada0..5a3ebbfaaee11f92f256474cb72f5d98ca66ad07 100644 (file)
@@ -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);
index 96a9e5d6c93292f9c6d101d56b9b8f904ebdce2a..6bb123fc72a71ea3a29e0a74fca174f437a0676c 100644 (file)
@@ -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");
index 45e91a8bbfe7c3e5ec49b975a219187f002d2a15..7e84f798a57f746598a8723a02329b7bf13390f8 100644 (file)
@@ -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");
index 101617fa876be0b09464df81cd06e419f9ffb1a6..b7863332e6888837840a46995e0361adb8663c17 100644 (file)
@@ -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);
index 68d49769bcfdc5834422b73c7c68c8c2062287ab..972043eeb25f672c9ec02d9f13232c4ca80d98b1 100644 (file)
@@ -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);
index b3139c6931998003757d797991258881b79d02f9..1d84ab92760fbd3db0864b130e4ed072f26ff21f 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <urcu/list.h>
 
@@ -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;
        }
 
index d52d4622a9c3f3b1dfa34decf94d20bceaa8ecfa..9957b378162b897a8743c8897425da51d27e0cb7 100644 (file)
@@ -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;
+}
index b0e44f66e01c4fb47f64820a1e61a162c33ba95e..662975a7613cb8cf9e333f75792c1632ff1b94cf 100644 (file)
@@ -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);
This page took 0.031044 seconds and 4 git commands to generate.