From 6caa2bcc3ec40374ae1c3b81c0179eb3f693de84 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 14 Nov 2011 09:40:48 -0500 Subject: [PATCH] Fix incorrect POPT_ARG_STRING usage Signed-off-by: Mathieu Desnoyers --- lttng/commands/add_context.c | 19 +++++-------------- lttng/commands/calibrate.c | 3 +-- lttng/commands/disable_channels.c | 3 +-- lttng/commands/disable_events.c | 3 +-- lttng/commands/enable_channels.c | 3 +-- lttng/commands/list.c | 3 +-- 6 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lttng/commands/add_context.c b/lttng/commands/add_context.c index dd13d223b..02220415d 100644 --- a/lttng/commands/add_context.c +++ b/lttng/commands/add_context.c @@ -42,6 +42,7 @@ static int opt_pid_all; static int opt_userspace; static char *opt_cmd_name; static pid_t opt_pid; +static char *opt_type; enum { OPT_HELP = 1, @@ -143,7 +144,7 @@ static struct poptOption long_options[] = { {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, - {"type", 't', POPT_ARG_STRING, 0, OPT_TYPE, 0, 0}, + {"type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; @@ -416,7 +417,6 @@ error: int cmd_add_context(int argc, const char **argv) { int index, opt, ret = CMD_SUCCESS; - char *tmp; static poptContext pc; struct ctx_type *type, *tmptype; char *session_name = NULL; @@ -436,32 +436,23 @@ int cmd_add_context(int argc, const char **argv) ret = CMD_SUCCESS; goto end; case OPT_TYPE: - /* Mandatory field */ - tmp = poptGetOptArg(pc); - if (tmp == NULL) { - usage(stderr); - ret = CMD_ERROR; - free(tmp); - goto end; - } type = malloc(sizeof(struct ctx_type)); if (type == NULL) { perror("malloc ctx_type"); ret = -1; goto end; } - index = find_ctx_type_idx(tmp); + index = find_ctx_type_idx(opt_type); if (index < 0) { - ERR("Unknown context type %s", tmp); + ERR("Unknown context type %s", opt_type); goto end; } type->opt = &ctx_opts[index]; if (type->opt->ctx_type == -1) { - ERR("Unknown context type %s", tmp); + ERR("Unknown context type %s", opt_type); } else { cds_list_add(&type->list, &ctx_type_list.head); } - free(tmp); break; case OPT_USERSPACE: opt_userspace = 1; diff --git a/lttng/commands/calibrate.c b/lttng/commands/calibrate.c index 6979ef6ea..1219685e7 100644 --- a/lttng/commands/calibrate.c +++ b/lttng/commands/calibrate.c @@ -56,7 +56,7 @@ static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, @@ -201,7 +201,6 @@ int cmd_calibrate(int argc, const char **argv) break; case OPT_USERSPACE: opt_userspace = 1; - opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr); diff --git a/lttng/commands/disable_channels.c b/lttng/commands/disable_channels.c index 262165eb3..a45f3ef09 100644 --- a/lttng/commands/disable_channels.c +++ b/lttng/commands/disable_channels.c @@ -49,7 +49,7 @@ static struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0} @@ -148,7 +148,6 @@ int cmd_disable_channels(int argc, const char **argv) goto end; case OPT_USERSPACE: opt_userspace = 1; - opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr); diff --git a/lttng/commands/disable_events.c b/lttng/commands/disable_events.c index 09b61cbe2..13ebd6c3a 100644 --- a/lttng/commands/disable_events.c +++ b/lttng/commands/disable_events.c @@ -53,7 +53,7 @@ static struct poptOption long_options[] = { {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0}, {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0} @@ -182,7 +182,6 @@ int cmd_disable_events(int argc, const char **argv) goto end; case OPT_USERSPACE: opt_userspace = 1; - opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr); diff --git a/lttng/commands/enable_channels.c b/lttng/commands/enable_channels.c index aac5fa497..48e83df28 100644 --- a/lttng/commands/enable_channels.c +++ b/lttng/commands/enable_channels.c @@ -58,7 +58,7 @@ static struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, {"discard", 0, POPT_ARG_NONE, 0, OPT_DISCARD, 0, 0}, @@ -235,7 +235,6 @@ int cmd_enable_channels(int argc, const char **argv) break; case OPT_USERSPACE: opt_userspace = 1; - opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr); diff --git a/lttng/commands/list.c b/lttng/commands/list.c index e2d5b6643..fcfaa3f23 100644 --- a/lttng/commands/list.c +++ b/lttng/commands/list.c @@ -48,7 +48,7 @@ static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0}, {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0}, @@ -481,7 +481,6 @@ int cmd_list(int argc, const char **argv) goto end; case OPT_USERSPACE: opt_userspace = 1; - opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr); -- 2.34.1