Add CMD_WARNING error code
authorDavid Goulet <dgoulet@efficios.com>
Fri, 27 Jan 2012 17:43:54 +0000 (12:43 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 27 Jan 2012 17:48:13 +0000 (12:48 -0500)
The CMD_WARNING is returned if at least one command went wrong and at
least one succeeded. This shoudl tell the user that there is an error
message on stderr but the rest of the command went well.

One use case for that is the multiple -t of add_context. If one of them
fails, this code is returned.

This error code is added at the end of the enum so the previous CMD code
are not changed.

Also, if the tracer (-k/-u) is not specified, CMD_ERROR is returned
instead of CMD_UNDEFINED which makes way more sense.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng/command.h
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/lttng.c

index 09ce7c0ebbc5c034f5290f97040dc7a220f04319..dcad0a1383524eb5f6a856547d8d88a16f1eb872 100644 (file)
@@ -31,6 +31,7 @@ enum cmd_error_code {
        CMD_ERROR,
        CMD_UNDEFINED,
        CMD_FATAL,
+       CMD_WARNING,
 };
 
 struct cmd_struct {
index 73aff31130e8e5e5f5489d988bff3583ae8ecc86..a7ab4268ac5401805d83d675639962d834f0fb50 100644 (file)
@@ -361,7 +361,7 @@ end:
  */
 static int add_context(char *session_name)
 {
-       int ret = CMD_SUCCESS;
+       int ret = CMD_SUCCESS, warn = 0;
        struct lttng_event_context context;
        struct lttng_domain dom;
        struct ctx_type *type;
@@ -373,7 +373,7 @@ static int add_context(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
@@ -404,6 +404,7 @@ static int add_context(char *session_name)
                                opt_channel_name);
                if (ret < 0) {
                        ERR("%s: ", type->opt->symbol);
+                       warn = 1;
                        continue;
                } else {
                        MSG("%s context %s added to %s event in %s",
@@ -418,6 +419,13 @@ static int add_context(char *session_name)
 error:
        lttng_destroy_handle(handle);
 
+       /*
+        * This means that at least one add_context failed and tells the user to
+        * look on stderr for error(s).
+        */
+       if (warn) {
+               ret = CMD_WARNING;
+       }
        return ret;
 }
 
index 2c1adb16c747d46ba2f7d2c27db1051ea94656b3..a3c7b5241a03cc0d539e94688f8698c4ebf07c7d 100644 (file)
@@ -134,7 +134,7 @@ static int calibrate_lttng(void)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
index 55564bc3d604eebc96968f25fac779152238e7bf..bdbb657921ce3483d052dca50b9e0f7a3831eba2 100644 (file)
@@ -99,7 +99,7 @@ static int disable_channels(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
index ff42da0e001c552c6b6f49c3d9a58b3126ecc4c1..7f7b50c78f2bb732500c21e187b28635f084f6a5 100644 (file)
@@ -123,7 +123,7 @@ static int disable_events(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
index e27fe88cecff1a826e62e849539bdaa4187a8a93..03de5241d59c6536578c328113704c40867262c5 100644 (file)
@@ -162,7 +162,7 @@ static int enable_channel(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
index 41a25730cdc4f5495d534fce5d21214ee46d9305..3f30ab8ba5156449ee3dba7084f957bbf7027664 100644 (file)
@@ -235,7 +235,7 @@ static int enable_events(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
-               ret = CMD_UNDEFINED;
+               ret = CMD_ERROR;
                goto error;
        }
 
index 5988c419d5febc17cf1856f66b6ced21b4d80ef5..31b4714db11ae59f4a8ad0d104bbebecb58d0bba 100644 (file)
@@ -263,6 +263,9 @@ static int handle_command(int argc, char **argv)
                if (strcmp(argv[0], cmd->name) == 0) {
                        ret = cmd->func(argc, (const char**) argv);
                        switch (ret) {
+                       case CMD_WARNING:
+                               WARN("Some command(s) went wrong");
+                               break;
                        case CMD_ERROR:
                                ERR("Command error");
                                break;
This page took 0.030982 seconds and 4 git commands to generate.