From: Julien Desfossez Date: Wed, 21 Feb 2018 21:57:36 +0000 (-0500) Subject: Fix: error out on leftover arguments X-Git-Tag: v2.9.8~4 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=266d3dd051c2c5e2a23009afbdc88b72c0fded5b;p=lttng-tools.git Fix: error out on leftover arguments All the commands currently ignore leftover arguments, this can lead to wrong usage of the commands and waste of time debugging. For example, this command enables the vpid context on all channels instead of only on the "mychan" channel: $ lttng add-context -u mychan -t vpid The correct usage is: $ lttng add-context -u -c mychan -t vpid We now output an error on leftover arguments: $ lttng add-context -u mychan -t vpid Error: Unknown argument: mychan Error: Command error Some commands accept one leftover argument (create, start, stop, destroy), so we check if there are other leftovers: $ lttng create mysess allo Error: Unknown argument: allo Error: Command error Only the snapshot command is not handled since it has a second level of command and does not consume the popt arguments. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index df722bb24..11c3372ad 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -892,6 +892,7 @@ int cmd_add_context(int argc, const char **argv) static poptContext pc; struct ctx_type *type, *tmptype; char *session_name = NULL; + const char *leftover = NULL; if (argc < 2) { ret = CMD_ERROR; @@ -938,6 +939,13 @@ int cmd_add_context(int argc, const char **argv) } } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + opt_jul + opt_log4j); if (ret) { diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 40d2a77d9..83f0af65d 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -619,6 +619,7 @@ int cmd_create(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; char *opt_arg = NULL; + const char *leftover = NULL; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -713,6 +714,13 @@ int cmd_create(int argc, const char **argv) } opt_session_name = (char*) poptGetArg(pc); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + command_ret = create_session(); if (command_ret) { success = 0; diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.c index 0314b767e..b17f4c516 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -168,6 +168,7 @@ int cmd_destroy(int argc, const char **argv) int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; struct lttng_session *sessions; int count; @@ -274,6 +275,14 @@ int cmd_destroy(int argc, const char **argv) } } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + success = 0; + goto mi_closing; + } + mi_closing: /* Mi closing */ if (lttng_opt_mi) { diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 678af746d..57391128e 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -210,6 +210,7 @@ int cmd_disable_channels(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -244,6 +245,13 @@ int cmd_disable_channels(int argc, const char **argv) goto end; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 238f8463f..3c53c75c2 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -322,6 +322,7 @@ int cmd_disable_events(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; int event_type = -1; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -392,6 +393,13 @@ int cmd_disable_events(int argc, const char **argv) goto end; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 9a990030d..66caa79a2 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -330,6 +330,7 @@ int cmd_enable_channels(int argc, const char **argv) static poptContext pc; char *session_name = NULL; char *opt_arg = NULL; + const char *leftover = NULL; init_channel_config(); @@ -545,6 +546,14 @@ int cmd_enable_channels(int argc, const char **argv) goto mi_closing; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + success = 0; + goto mi_closing; + } + if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 8a32837e6..f5e8ba61a 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -1249,6 +1249,7 @@ int cmd_enable_events(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; int event_type = -1; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -1348,6 +1349,13 @@ int cmd_enable_events(int argc, const char **argv) goto end; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 9aa28b57a..8c6d1ef4a 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -1691,7 +1691,7 @@ end: int cmd_list(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; - const char *session_name; + const char *session_name, *leftover = NULL; static poptContext pc; struct lttng_domain domain; struct lttng_domain *domains = NULL; @@ -1752,6 +1752,13 @@ int cmd_list(int argc, const char **argv) session_name = poptGetArg(pc); DBG2("Session name: %s", session_name); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + if (opt_kernel) { domain.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c index 0516351ea..e65042cd4 100644 --- a/src/bin/lttng/commands/load.c +++ b/src/bin/lttng/commands/load.c @@ -157,6 +157,7 @@ int cmd_load(int argc, const char **argv) poptContext pc; struct lttng_load_session_attr *session_attr = NULL; char *input_path = NULL; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, load_opts, 0); poptReadDefaultConfig(pc, 0); @@ -200,6 +201,13 @@ int cmd_load(int argc, const char **argv) } } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/src/bin/lttng/commands/save.c b/src/bin/lttng/commands/save.c index ee3e17c66..808216bf9 100644 --- a/src/bin/lttng/commands/save.c +++ b/src/bin/lttng/commands/save.c @@ -121,7 +121,7 @@ int cmd_save(int argc, const char **argv) { int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success; int opt; - const char *session_name = NULL; + const char *session_name = NULL, *leftover = NULL; poptContext pc; struct lttng_save_session_attr *attr; @@ -158,6 +158,13 @@ int cmd_save(int argc, const char **argv) } } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + attr = lttng_save_session_attr_create(); if (!attr) { ret = CMD_FATAL; diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c index 03d99cf41..5df246225 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -138,6 +138,7 @@ int cmd_start(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -158,6 +159,13 @@ int cmd_start(int argc, const char **argv) opt_session_name = (char*) poptGetArg(pc); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.c index c38fc894a..c5677b4a7 100644 --- a/src/bin/lttng/commands/stop.c +++ b/src/bin/lttng/commands/stop.c @@ -166,6 +166,7 @@ int cmd_stop(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -222,6 +223,13 @@ int cmd_stop(int argc, const char **argv) opt_session_name = (char*) poptGetArg(pc); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + command_ret = stop_tracing(); if (command_ret) { success = 0; diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index db13ee227..1e6852e79 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -409,6 +409,7 @@ int cmd_view(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; static poptContext pc; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -433,6 +434,13 @@ int cmd_view(int argc, const char **argv) opt_session_name = (char*) poptGetArg(pc); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + ret = view_trace(); end: