From: David Goulet Date: Fri, 27 Jan 2012 17:43:54 +0000 (-0500) Subject: Add CMD_WARNING error code X-Git-Tag: v2.0-pre19~45 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d16c1a4ce20ed71733c02353383f1a3058fe9ed2;p=lttng-tools.git Add CMD_WARNING error code 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 --- diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index 09ce7c0eb..dcad0a138 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -31,6 +31,7 @@ enum cmd_error_code { CMD_ERROR, CMD_UNDEFINED, CMD_FATAL, + CMD_WARNING, }; struct cmd_struct { diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index 73aff3113..a7ab4268a 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -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; } diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index 2c1adb16c..a3c7b5241 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -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; } diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 55564bc3d..bdbb65792 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -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; } diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index ff42da0e0..7f7b50c78 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -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; } diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index e27fe88ce..03de5241d 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -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; } diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 41a25730c..3f30ab8ba 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -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; } diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 5988c419d..31b4714db 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -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;