From 6047170fdd6ff755d4ebe0f4a598e9d1caf24960 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 8 Aug 2018 17:48:24 -0400 Subject: [PATCH] Remove generic error reporting from the lttng client MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Unsuccessful command results are reported by the lttng client which often results in strange error messages of the form: Error: Could not rotate ... Error: Command error Considering that most commands correctly report their errors, it is safe to remove those generic error reports. Signed-off-by: Jérémie Galarneau --- src/bin/lttng/lttng.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 08eea54a6..8842a03b5 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -253,6 +253,23 @@ end: return ret; } +static bool command_exists(const char *command) +{ + const struct cmd_struct *cmd = commands; + bool exists = false; + + while (cmd->name != NULL) { + if (!strcmp(command, cmd->name)) { + exists = true; + goto end; + } + cmd++; + } + +end: + return exists; +} + static void show_basic_help(void) { puts("Usage: lttng [--group=GROUP] [--mi=TYPE] [--no-sessiond | --sessiond-path=PATH]"); @@ -403,19 +420,19 @@ static int parse_args(int argc, char **argv) ret = handle_command(argc - optind, argv + optind); switch (ret) { case CMD_WARNING: - WARN("Some command(s) went wrong"); - break; case CMD_ERROR: - ERR("Command error"); break; case CMD_UNDEFINED: - ERR("Undefined command or invalid arguments"); + if (!command_exists(*(argv + optind))) { + MSG("lttng: %s is not an lttng command. See 'lttng --help'.", + *(argv + optind)); + } else { + ERR("Unrecognized argument used with \'%s\' command", + *(argv + optind)); + } break; case CMD_FATAL: - ERR("Fatal error"); - break; case CMD_UNSUPPORTED: - ERR("Unsupported command"); break; case -1: ret = 1; -- 2.34.1