Fix: lttng UI exit value and error message
authorDavid Goulet <dgoulet@efficios.com>
Tue, 20 Mar 2012 18:27:12 +0000 (14:27 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 20 Mar 2012 18:27:12 +0000 (14:27 -0400)
Change lttcomm error code starting value from 1000 to 10. This way, bash
can return the exact error code since 255 is the maximum.

Fix multiple warning, error and message output.

Some return code could still be not "standardize" but for stable it's
ok. Fixes can come later on.

(close #105)

Signed-off-by: David Goulet <dgoulet@efficios.com>
13 files changed:
src/bin/lttng-sessiond/channel.c
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/kernel.c
src/bin/lttng/command.h
src/bin/lttng/commands/create.c
src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/start.c
src/bin/lttng/commands/stop.c
src/bin/lttng/lttng.c
src/common/sessiond-comm/sessiond-comm.c
src/common/sessiond-comm/sessiond-comm.h

index 57c5c422507b26bc34a74301757ec66ab37963dd..4ec12302b027e83ea3f63b5da862ce04737ecab0 100644 (file)
@@ -121,6 +121,9 @@ int channel_kernel_enable(struct ltt_kernel_session *ksession,
                        ret = LTTCOMM_KERN_CHAN_ENABLE_FAIL;
                        goto error;
                }
+       } else {
+               ret = LTTCOMM_KERN_CHAN_EXIST;
+               goto error;
        }
 
        ret = LTTCOMM_OK;
@@ -179,6 +182,7 @@ int channel_ust_enable(struct ltt_ust_session *usess, int domain,
        /* If already enabled, everything is OK */
        if (uchan->enabled) {
                DBG3("Channel %s already enabled. Skipping", uchan->name);
+               ret = LTTCOMM_UST_CHAN_EXIST;
                goto end;
        }
 
index 388e688e64e9a831ddd18664df572adca85ca150..ac4b0b4a365f7f493973f7389cd58f241c8292ae 100644 (file)
@@ -147,7 +147,12 @@ int event_kernel_enable_tracepoint(struct ltt_kernel_session *ksession,
                        ret = LTTCOMM_KERN_ENABLE_FAIL;
                        goto end;
                }
+       } else {
+               /* At this point, the event is considered enabled */
+               ret = LTTCOMM_KERN_EVENT_EXIST;
+               goto end;
        }
+
        ret = LTTCOMM_OK;
 end:
        return ret;
index b1ff2ec48d10f58e57fd9be0abcb11810a064ef0..dd815c44536fd8629d01537d6a6d749f70033147 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <common/common.h>
 #include <common/kernel-ctl/kernel-ctl.h>
+#include <common/sessiond-comm/sessiond-comm.h>
 
 #include "kernel.h"
 #include "kern-modules.h"
@@ -290,8 +291,15 @@ int kernel_enable_event(struct ltt_kernel_event *event)
        int ret;
 
        ret = kernctl_enable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               PERROR("enable kernel event");
+       if (ret < 0) {
+               switch (errno) {
+               case EEXIST:
+                       ret = LTTCOMM_KERN_EVENT_EXIST;
+                       break;
+               default:
+                       PERROR("enable kernel event");
+                       break;
+               }
                goto error;
        }
 
@@ -312,8 +320,15 @@ int kernel_disable_event(struct ltt_kernel_event *event)
        int ret;
 
        ret = kernctl_disable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               PERROR("disable kernel event");
+       if (ret < 0) {
+               switch (errno) {
+               case EEXIST:
+                       ret = LTTCOMM_KERN_EVENT_EXIST;
+                       break;
+               default:
+                       PERROR("disable kernel event");
+                       break;
+               }
                goto error;
        }
 
index 922a3d4f2e2c98fa8d25ac4efdd96af46fe21d9b..27de0d5a0f1c61b9218c98b2a5e3d356b1612a50 100644 (file)
@@ -26,7 +26,7 @@
 #include "utils.h"
 
 enum cmd_error_code {
-       CMD_SUCCESS,
+       CMD_SUCCESS = 0,
        CMD_ERROR,
        CMD_UNDEFINED,
        CMD_FATAL,
index fcf6e128941877a46322827b046e3d79e5043c6d..b1f3e8a777a0420ca4f5de66c7c9032118780015 100644 (file)
@@ -28,6 +28,8 @@
 #include "../command.h"
 #include "../utils.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_output_path;
 static char *opt_session_name;
 
@@ -119,6 +121,11 @@ static int create_session()
        ret = lttng_create_session(session_name, traces_path);
        if (ret < 0) {
                /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_EXIST_SESS:
+                       WARN("Session %s already exists", session_name);
+                       break;
+               }
                goto error;
        }
 
index 49b263cc2a1dc6c36777a1f2fa982989eb0583c1..a179da83f576ce3700ba3d2148df6235d3b2f2fb 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -76,7 +78,13 @@ static int destroy_session()
 
        ret = lttng_destroy_session(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_SESS_NOT_FOUND:
+                       WARN("Session name %s not found", session_name);
+                       break;
+               default:
+                       break;
+               }
                goto free_name;
        }
 
index 393fb32ca3263e501dd92262b6d4faa95c3effca..9b5f8d64d302b276f3faee598c30e43dfcde28a2 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "../command.h"
 
+#include <src/common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_channels;
 static int opt_kernel;
 static char *opt_session_name;
@@ -189,8 +191,17 @@ static int enable_channel(char *session_name)
 
                ret = lttng_enable_channel(handle, &chan);
                if (ret < 0) {
-                       ERR("Channel %s: %s (session %s)", channel_name,
-                                       lttng_strerror(ret), session_name);
+                       switch (-ret) {
+                       case LTTCOMM_KERN_CHAN_EXIST:
+                       case LTTCOMM_UST_CHAN_EXIST:
+                               WARN("Channel %s: %s (session %s", channel_name,
+                                               lttng_strerror(ret), session_name);
+                               goto error;
+                       default:
+                               ERR("Channel %s: %s (session %s)", channel_name,
+                                               lttng_strerror(ret), session_name);
+                               break;
+                       }
                        warn = 1;
                } else {
                        MSG("%s channel %s enabled for session %s",
index 278090f352c8295dd69341d30a5964afbde17940..860472fa9c370e8a1d934065d9c2cde54ca0975a 100644 (file)
@@ -27,6 +27,7 @@
 #include <ctype.h>
 
 #include "../command.h"
+#include <src/common/sessiond-comm/sessiond-comm.h>
 
 static char *opt_event_list;
 static int opt_event_type;
@@ -345,7 +346,16 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       goto error;
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel events already enabled (channel %s, session %s)",
+                                               channel_name, session_name);
+                               goto end;
+                       default:
+                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
                }
 
                switch (opt_event_type) {
@@ -492,8 +502,17 @@ static int enable_events(char *session_name)
 
                ret = lttng_enable_event(handle, &ev, channel_name);
                if (ret < 0) {
-                       ERR("Event %s: %s (channel %s, session %s)", event_name,
-                                       lttng_strerror(ret), channel_name, session_name);
+                       /* Turn ret to positive value to handle the positive error code */
+                       switch (-ret) {
+                       case LTTCOMM_KERN_EVENT_EXIST:
+                               WARN("Kernel event %s already enabled (channel %s, session %s)",
+                                               event_name, channel_name, session_name);
+                               break;
+                       default:
+                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                                               lttng_strerror(ret), channel_name, session_name);
+                               break;
+                       }
                        warn = 1;
                } else {
                        MSG("%s event %s created in channel %s",
index 0f44f4cdac511a750d884546cc65d6a96001d52f..44554fb37e223d11f62cb0d0f7bce33e096f79f2 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -79,7 +81,14 @@ static int start_tracing(void)
 
        ret = lttng_start_tracing(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_TRACE_ALREADY_STARTED:
+                       WARN("Tracing already started for session %s", session_name);
+                       break;
+               default:
+                       ERR("%s", lttng_strerror(ret));
+                       break;
+               }
                goto free_name;
        }
 
index fbabc510039f2f5fc8c5486b6240bf64d6326780..6ed67fdabcaaf0194cbbe911c3853609aa3720de 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "../command.h"
 
+#include <common/sessiond-comm/sessiond-comm.h>
+
 static char *opt_session_name;
 
 enum {
@@ -75,7 +77,14 @@ static int stop_tracing(void)
 
        ret = lttng_stop_tracing(session_name);
        if (ret < 0) {
-               /* Don't set ret so lttng can interpret the sessiond error. */
+               switch (-ret) {
+               case LTTCOMM_TRACE_ALREADY_STOPPED:
+                       WARN("Tracing already stopped for session %s", session_name);
+                       break;
+               default:
+                       ERR("%s", lttng_strerror(ret));
+                       break;
+               }
                goto free_name;
        }
 
index 61d31bf43199c9238e9774ed88225a35d6ddf51d..8ddba13f4384af3e069608d7f6b4340ea664389c 100644 (file)
@@ -501,7 +501,9 @@ static int parse_args(int argc, char **argv)
        case 0:
                break;
        default:
-               ERR("%s", lttng_strerror(ret));
+               if (ret < 0) {
+                       ret = -ret;
+               }
                break;
        }
 
index bb4a11934f2c42c9a00ae2a1475844969789b4ac..89ea207e0667ca519b7113afd54f933a688c7bd0 100644 (file)
@@ -60,6 +60,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_VERSION) ] = "Kernel tracer version is not compatible",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_EVENT_EXIST) ] = "Kernel event already exists",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_EXIST) ] = "Kernel channel already exists",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_DISABLE_FAIL) ] = "Disable kernel channel failed",
index dd673d8246169a1453eefa4402b66f14c17fba68..dbb744c0c1bfce51be428184e38176b1251dee01 100644 (file)
@@ -68,7 +68,7 @@ enum lttcomm_sessiond_command {
  * lttcomm error code.
  */
 enum lttcomm_return_code {
-       LTTCOMM_OK = 1000,                              /* Ok */
+       LTTCOMM_OK = 10,                                /* Ok */
        LTTCOMM_ERR,                                    /* Unknown Error */
        LTTCOMM_UND,                                    /* Undefine command */
        LTTCOMM_NOT_IMPLEMENTED,        /* Command not implemented */
@@ -95,6 +95,7 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_VERSION,           /* Kernel tracer version is not compatible */
        LTTCOMM_KERN_EVENT_EXIST,       /* Kernel event already exists */
        LTTCOMM_KERN_SESS_FAIL,                 /* Kernel create session failed */
+       LTTCOMM_KERN_CHAN_EXIST,        /* Kernel channel already exists */
        LTTCOMM_KERN_CHAN_FAIL,                 /* Kernel create channel failed */
        LTTCOMM_KERN_CHAN_NOT_FOUND,    /* Kernel channel not found */
        LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */
This page took 0.032523 seconds and 4 git commands to generate.