From: Julien Desfossez Date: Wed, 21 Feb 2018 21:57:36 +0000 (-0500) Subject: Fix: error out on leftover arguments X-Git-Tag: v2.11.0-rc1~384 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=68c7f6e55254fd6e54d7bb4a6c1316bb77843a6e;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 209a9f4eb..d9121b02a 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -898,6 +898,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; @@ -944,6 +945,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 d075f64b9..faf9f3e0d 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -625,6 +625,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); @@ -719,6 +720,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 02c7139c3..6878aaa0d 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -174,6 +174,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; @@ -280,6 +281,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 775ff8959..936884e1f 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -216,6 +216,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); @@ -250,6 +251,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 269620178..290e72791 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -328,6 +328,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); @@ -398,6 +399,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 cb9f44a63..9c84d0263 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -400,6 +400,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(); @@ -693,6 +694,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 97a36b311..05f20f72d 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -1264,6 +1264,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); @@ -1363,6 +1364,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 a166fd2b3..898c0de6a 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -1776,7 +1776,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; @@ -1837,6 +1837,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 ad6184923..07ef1214f 100644 --- a/src/bin/lttng/commands/load.c +++ b/src/bin/lttng/commands/load.c @@ -163,6 +163,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); @@ -206,6 +207,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 4ba902436..924ddcbcd 100644 --- a/src/bin/lttng/commands/save.c +++ b/src/bin/lttng/commands/save.c @@ -127,7 +127,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; @@ -164,6 +164,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 0287fc7e8..65b222924 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -144,6 +144,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); @@ -164,6 +165,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 336d88765..9d211d68b 100644 --- a/src/bin/lttng/commands/stop.c +++ b/src/bin/lttng/commands/stop.c @@ -172,6 +172,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); @@ -228,6 +229,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 c9a5fdc3e..faca60de8 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -415,6 +415,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); @@ -439,6 +440,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: