From: Thibault, Daniel Date: Wed, 1 Feb 2012 18:59:50 +0000 (-0500) Subject: Fix return value and mem leak for all commands X-Git-Tag: v2.0-pre19~19 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ca1c3607d2f5654163875cda874f43971df0f696;p=lttng-tools.git Fix return value and mem leak for all commands Add poptFreeContext(), send --help to stdout and default return value to CMD_SUCCESS Also fix some return values for list.c Signed-off-by: Daniel U. Thibault Signed-off-by: David Goulet --- diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index ce65024f5..a1d776d6c 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -466,7 +466,6 @@ int cmd_add_context(int argc, const char **argv) switch (opt) { case OPT_HELP: usage(stdout); - ret = CMD_SUCCESS; goto end; case OPT_TYPE: /* @@ -505,7 +504,6 @@ int cmd_add_context(int argc, const char **argv) break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -532,5 +530,6 @@ end: free(type); } + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index a60cadfa0..547b349e4 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -187,7 +187,7 @@ error: */ int cmd_calibrate(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -200,7 +200,6 @@ int cmd_calibrate(int argc, const char **argv) switch (opt) { case OPT_HELP: usage(stdout); - ret = CMD_SUCCESS; goto end; case OPT_TRACEPOINT: ret = CMD_UNDEFINED; @@ -225,7 +224,6 @@ int cmd_calibrate(int argc, const char **argv) break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -237,5 +235,6 @@ int cmd_calibrate(int argc, const char **argv) ret = calibrate_lttng(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 3a4b6f30f..7ed663259 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -178,5 +178,6 @@ int cmd_create(int argc, const char **argv) ret = create_session(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.c index 39b4e9a2f..b0262ea2f 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -117,11 +117,10 @@ int cmd_destroy(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -135,5 +134,6 @@ int cmd_destroy(int argc, const char **argv) ret = destroy_session(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index bdbb65792..05ee0e6ef 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -140,7 +140,7 @@ error: */ int cmd_disable_channels(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; @@ -150,15 +150,13 @@ int cmd_disable_channels(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -171,14 +169,14 @@ int cmd_disable_channels(int argc, const char **argv) if (opt_channels == NULL) { ERR("Missing channel name(s).\n"); usage(stderr); - ret = CMD_SUCCESS; + ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { - ret = -1; + ret = CMD_ERROR; goto end; } } else { @@ -188,5 +186,6 @@ int cmd_disable_channels(int argc, const char **argv) ret = disable_channels(session_name); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 7f7b50c78..4ddcf5431 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -198,7 +198,7 @@ error: */ int cmd_disable_events(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; @@ -208,15 +208,13 @@ int cmd_disable_events(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -229,14 +227,14 @@ int cmd_disable_events(int argc, const char **argv) if (opt_event_list == NULL && opt_disable_all == 0) { ERR("Missing event name(s).\n"); usage(stderr); - ret = CMD_SUCCESS; + ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { - ret = -1; + ret = CMD_ERROR; goto end; } } else { @@ -246,5 +244,6 @@ int cmd_disable_events(int argc, const char **argv) ret = disable_events(session_name); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 03de5241d..19b6b260b 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -219,7 +219,7 @@ static void init_channel_config(void) */ int cmd_enable_channels(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; @@ -231,8 +231,7 @@ int cmd_enable_channels(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_DISCARD: chan.attr.overwrite = 0; @@ -243,18 +242,22 @@ int cmd_enable_channels(int argc, const char **argv) DBG("Channel set to overwrite"); break; case OPT_SUBBUF_SIZE: + /* TODO Replace atol with strtol and check for errors */ chan.attr.subbuf_size = atol(poptGetOptArg(pc)); DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size); break; case OPT_NUM_SUBBUF: + /* TODO Replace atoi with strtol and check for errors */ chan.attr.num_subbuf = atoi(poptGetOptArg(pc)); DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf); break; case OPT_SWITCH_TIMER: + /* TODO Replace atoi with strtol and check for errors */ chan.attr.switch_timer_interval = atoi(poptGetOptArg(pc)); DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval); break; case OPT_READ_TIMER: + /* TODO Replace atoi with strtol and check for errors */ chan.attr.read_timer_interval = atoi(poptGetOptArg(pc)); DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval); break; @@ -263,7 +266,6 @@ int cmd_enable_channels(int argc, const char **argv) break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -276,14 +278,14 @@ int cmd_enable_channels(int argc, const char **argv) if (opt_channels == NULL) { ERR("Missing channel name.\n"); usage(stderr); - ret = CMD_SUCCESS; + ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { - ret = -1; + ret = CMD_ERROR; goto end; } } else { @@ -293,5 +295,6 @@ int cmd_enable_channels(int argc, const char **argv) ret = enable_channel(session_name); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 1fcc81acb..49bae56b2 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -417,7 +417,7 @@ error: */ int cmd_enable_events(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; @@ -430,8 +430,7 @@ int cmd_enable_events(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_TRACEPOINT: opt_event_type = LTTNG_EVENT_TRACEPOINT; @@ -461,7 +460,6 @@ int cmd_enable_events(int argc, const char **argv) break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -474,14 +472,14 @@ int cmd_enable_events(int argc, const char **argv) if (opt_event_list == NULL && opt_enable_all == 0) { ERR("Missing event name(s).\n"); usage(stderr); - ret = CMD_SUCCESS; + ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { - ret = -1; + ret = CMD_ERROR; goto end; } } else { @@ -495,5 +493,6 @@ end: free(session_name); } + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 4b8a07c48..d84fd2ba9 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -541,6 +541,7 @@ int cmd_list(int argc, const char **argv) if (argc < 1) { usage(stderr); + ret = CMD_ERROR; goto end; } @@ -550,14 +551,13 @@ int cmd_list(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); + usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -579,6 +579,7 @@ int cmd_list(int argc, const char **argv) handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { + ret = CMD_FATAL; goto end; } @@ -586,18 +587,21 @@ int cmd_list(int argc, const char **argv) if (!opt_kernel && !opt_userspace) { ret = list_sessions(NULL); if (ret < 0) { + ret = CMD_ERROR; goto end; } } if (opt_kernel) { ret = list_kernel_events(); if (ret < 0) { + ret = CMD_ERROR; goto end; } } if (opt_userspace) { ret = list_ust_events(); if (ret < 0) { + ret = CMD_ERROR; goto end; } } @@ -605,12 +609,16 @@ int cmd_list(int argc, const char **argv) /* List session attributes */ ret = list_sessions(session_name); if (ret < 0) { + ret = CMD_ERROR; goto end; } /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); + if (ret < 0) { + ret = CMD_ERROR; + } goto end; } @@ -618,13 +626,14 @@ int cmd_list(int argc, const char **argv) /* Channel listing */ ret = list_channels(opt_channel); if (ret < 0) { + ret = CMD_ERROR; goto end; } } else { /* We want all domain(s) */ nb_domain = lttng_list_domains(session_name, &domains); if (nb_domain < 0) { - ret = nb_domain; + ret = CMD_ERROR; goto end; } @@ -646,11 +655,13 @@ int cmd_list(int argc, const char **argv) handle = lttng_create_handle(session_name, &domains[i]); if (handle == NULL) { + ret = CMD_FATAL; goto end; } ret = list_channels(opt_channel); if (ret < 0) { + ret = CMD_ERROR; goto end; } } @@ -663,5 +674,6 @@ end: } lttng_destroy_handle(handle); + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c index f91935e04..fdeeaafb5 100644 --- a/src/bin/lttng/commands/set_session.c +++ b/src/bin/lttng/commands/set_session.c @@ -89,12 +89,10 @@ int cmd_set_session(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -107,11 +105,13 @@ int cmd_set_session(int argc, const char **argv) if (opt_session_name == NULL) { ERR("Missing session name"); usage(stderr); + ret = CMD_ERROR; goto end; } ret = set_session(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c index b2a498005..1db0a31c5 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -100,7 +100,7 @@ error: */ int cmd_start(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -109,12 +109,10 @@ int cmd_start(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -128,5 +126,6 @@ int cmd_start(int argc, const char **argv) ret = start_tracing(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.c index 82c9b4e13..689fe1b04 100644 --- a/src/bin/lttng/commands/stop.c +++ b/src/bin/lttng/commands/stop.c @@ -97,7 +97,7 @@ error: */ int cmd_stop(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -106,12 +106,10 @@ int cmd_stop(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -125,5 +123,6 @@ int cmd_stop(int argc, const char **argv) ret = stop_tracing(); end: + poptFreeContext(pc); return ret; } diff --git a/src/bin/lttng/commands/version.c b/src/bin/lttng/commands/version.c index f288ba4aa..030ccaae2 100644 --- a/src/bin/lttng/commands/version.c +++ b/src/bin/lttng/commands/version.c @@ -66,12 +66,10 @@ int cmd_version(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); - ret = CMD_SUCCESS; + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -85,5 +83,6 @@ int cmd_version(int argc, const char **argv) MSG("\nlttng is free software and under the GPL license."); end: + poptFreeContext(pc); return ret; }