Fix return value and mem leak for all commands
authorThibault, Daniel <Daniel.Thibault@drdc-rddc.gc.ca>
Wed, 1 Feb 2012 18:59:50 +0000 (13:59 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 1 Feb 2012 20:17:18 +0000 (15:17 -0500)
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 <daniel.thibault@drdc-rddc.gc.ca>
Signed-off-by: David Goulet <dgoulet@efficios.com>
13 files changed:
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/calibrate.c
src/bin/lttng/commands/create.c
src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/disable_channels.c
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/set_session.c
src/bin/lttng/commands/start.c
src/bin/lttng/commands/stop.c
src/bin/lttng/commands/version.c

index ce65024f5f6b912cbf2406d8be8e82018c2b9e90..a1d776d6cbb46da28b4128fd8d2d5fcacb27bf92 100644 (file)
@@ -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;
 }
index a60cadfa042a629eee9d97f1c4c1615a889e6656..547b349e4dbb713d67f6862d61debb74a4e57de8 100644 (file)
@@ -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;
 }
index 3a4b6f30ff826b3b72b971719b0f4a42d3cc0b1d..7ed663259ee7e13eb2ef3a47349f0c01a31dae9a 100644 (file)
@@ -178,5 +178,6 @@ int cmd_create(int argc, const char **argv)
        ret = create_session();
 
 end:
+       poptFreeContext(pc);
        return ret;
 }
index 39b4e9a2f6dbe00d0b6a63d6c372455dc07fbfb8..b0262ea2f0bbf5e1a3ec7e36925f3b3c9e1fccdd 100644 (file)
@@ -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;
 }
index bdbb657921ce3483d052dca50b9e0f7a3831eba2..05ee0e6ef65dca36c4d09efa4f65cf8d9bf21059 100644 (file)
@@ -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;
 }
index 7f7b50c78f2bb732500c21e187b28635f084f6a5..4ddcf5431a374f8bc9dc0fbedaa70b28bb5d4532 100644 (file)
@@ -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;
 }
index 03de5241d59c6536578c328113704c40867262c5..19b6b260bd7065e0b6490d8e247036483ecb14c6 100644 (file)
@@ -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;
 }
index 1fcc81acb64e360a88e7da2b503001a4097b77b4..49bae56b23872013abda97ffe665acfc014d72da 100644 (file)
@@ -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;
 }
index 4b8a07c48fc6aa29dc316711f8cf0774c6fbe334..d84fd2ba97d6e78551b3f07d07ea649d5dc6ffb5 100644 (file)
@@ -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;
 }
index f91935e045072d5d71bf551c0fbb8108b90ee6fe..fdeeaafb5ded5ab535c131046af90f179d19e684 100644 (file)
@@ -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;
 }
index b2a4980055f4c480a1798b5c599e872a81c1ac93..1db0a31c5b49a48efea44cdbd841d0801849c9f4 100644 (file)
@@ -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;
 }
index 82c9b4e13fb03baea2a3eff5146902ffbe60ddd3..689fe1b04998f8451d8c5018670ab5d1b25f1f65 100644 (file)
@@ -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;
 }
index f288ba4aa971e30e1e9c615f1f4dd629664b07ce..030ccaae2937d89f071563f78ee4f6dfc78f306d 100644 (file)
@@ -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;
 }
This page took 0.040217 seconds and 4 git commands to generate.