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, 24 Sep 2015 04:35:35 +0000 (00:35 -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/utils.c
src/bin/lttng/utils.h

index 7211dc5cb9498ed13f8fb42551b3491bbad1e1f8..8e0ae83bddf7f09457f572841853242a7a5a5c8b 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <urcu/list.h>
 
@@ -567,9 +568,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);
@@ -748,6 +747,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 567f4a5fa560b6b031ca02b505e4e8b286a84760..86e1838840be492a8f1c6c53041e8a9430dcce4a 100644 (file)
@@ -33,7 +33,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 */
@@ -50,6 +50,7 @@ enum {
        OPT_FUNCTION_ENTRY,
        OPT_SYSCALL,
        OPT_USERSPACE,
+       OPT_KERNEL,
        OPT_LIST_OPTIONS,
 };
 
@@ -59,7 +60,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},
@@ -68,6 +68,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
@@ -132,9 +133,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);
@@ -228,6 +228,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;
@@ -238,6 +241,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 27f1db5b845f738af0b7a97f4c1062774c8f828a..6a5c85521d2d35685df1a67840d5c65aab992816 100644 (file)
@@ -142,9 +142,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);
@@ -260,6 +259,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 b50882e04ff0d70d3518d173db856625d9eb3432..b75ee7b5395d1005b03ebe4993bd503cf5707691 100644 (file)
@@ -179,9 +179,8 @@ static int disable_events(char *session_name)
        } else if (opt_log4j) {
                dom.type = LTTNG_DOMAIN_LOG4J;
        } else {
-               print_missing_domain();
-               ret = CMD_ERROR;
-               goto error;
+               /* Checked by the caller. */
+               assert(0);
        }
 
        channel_name = opt_channel_name;
@@ -371,6 +370,13 @@ int cmd_disable_events(int argc, const char **argv)
                }
        }
 
+       ret = print_missing_or_multiple_domains(
+               opt_kernel + opt_userspace + opt_jul + opt_log4j);
+       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 6900dfde83e9c926ac59b7baec09fc8edbd69f24..e63ceb55f7ba526342039e3c0a21d4eaf0c68882 100644 (file)
@@ -219,9 +219,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);
@@ -569,6 +568,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 6ebf89f72f757565dd0edf98f154e338c2fcae4b..2fc24c5cce0807fc957128120117bcb64d3a8def 100644 (file)
@@ -676,9 +676,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) {
@@ -1105,9 +1104,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) {
@@ -1388,6 +1385,13 @@ int cmd_enable_events(int argc, const char **argv)
                }
        }
 
+       ret = print_missing_or_multiple_domains(
+               opt_kernel + opt_userspace + opt_jul + opt_log4j);
+       if (ret) {
+               ret = CMD_ERROR;
+               goto end;
+       }
+
        /* Mi check */
        if (lttng_opt_mi) {
                writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
index c271cbc6b82b74eec91cba27609e11d383369447..cb58f7604ed02a8cba613181924e15474f350ebe 100644 (file)
@@ -396,3 +396,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 ea92bb9bc0cf2968ab588aba7eacfda1ebbde459..7d383b2e6b85046a0607a3c0b30feb5948378a14 100644 (file)
@@ -52,11 +52,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.031673 seconds and 4 git commands to generate.