From: David Goulet Date: Tue, 20 Mar 2012 18:27:12 +0000 (-0400) Subject: Fix: lttng UI exit value and error message X-Git-Tag: v2.0.0-rc4~15 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4222434939b65c3abf144866564732d7fd14ed13;p=lttng-tools.git Fix: lttng UI exit value and error message 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 --- diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index 57c5c4225..4ec12302b 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -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; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 388e688e6..ac4b0b4a3 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -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; diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index b1ff2ec48..dd815c445 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -25,6 +25,7 @@ #include #include +#include #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; } diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index 922a3d4f2..27de0d5a0 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -26,7 +26,7 @@ #include "utils.h" enum cmd_error_code { - CMD_SUCCESS, + CMD_SUCCESS = 0, CMD_ERROR, CMD_UNDEFINED, CMD_FATAL, diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index fcf6e1289..b1f3e8a77 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -28,6 +28,8 @@ #include "../command.h" #include "../utils.h" +#include + 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; } diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.c index 49b263cc2..a179da83f 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -26,6 +26,8 @@ #include "../command.h" +#include + 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; } diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 393fb32ca..9b5f8d64d 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -27,6 +27,8 @@ #include "../command.h" +#include + 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", diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 278090f35..860472fa9 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -27,6 +27,7 @@ #include #include "../command.h" +#include 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", diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c index 0f44f4cda..44554fb37 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -26,6 +26,8 @@ #include "../command.h" +#include + 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; } diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.c index fbabc5100..6ed67fdab 100644 --- a/src/bin/lttng/commands/stop.c +++ b/src/bin/lttng/commands/stop.c @@ -26,6 +26,8 @@ #include "../command.h" +#include + 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; } diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 61d31bf43..8ddba13f4 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -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; } diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index bb4a11934..89ea207e0 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -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", diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index dd673d824..dbb744c0c 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -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 */