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>
Tue, 15 Sep 2015 17:00:18 +0000 (13:00 -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 5ac755199eead42c69e90befeecb3f4aec5bdc71..2e1c1c5b7e281bd64340f69d90b7f0172a786b0b 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <urcu/list.h>
 
@@ -562,9 +563,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);
@@ -740,6 +739,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 9a7eb0d40702b177edfd92c50bc964cb69420f9c..118a398578bacc8dc181d43456324b0909d0fc55 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;
 
 enum {
@@ -46,6 +46,7 @@ enum {
        OPT_FUNCTION_ENTRY,
        OPT_SYSCALL,
        OPT_USERSPACE,
+       OPT_KERNEL,
        OPT_LIST_OPTIONS,
 };
 
@@ -55,7 +56,7 @@ 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},
+       {"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},
        {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
@@ -100,9 +101,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);
@@ -196,6 +196,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;
@@ -206,6 +209,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 bb3fc551b1e30c6b86e782004163a695e7bbda5b..ea05574514ab698e06c65b46e4f7dce84e8c13f5 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.031158 seconds and 4 git commands to generate.