Fix return value and mem leak for all commands
[lttng-tools.git] / src / bin / lttng / commands / set_session.c
index 8a76403ad43d922eeb31c679a8632c88e5d7d876..fdeeaafb5ded5ab535c131046af90f179d19e684 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "../cmd.h"
-#include "../conf.h"
-#include "../utils.h"
+#include "../command.h"
 
 static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",           'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options",   0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -50,6 +50,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -88,8 +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);
                        goto end;
                default:
                        usage(stderr);
@@ -102,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;
 }
This page took 0.024161 seconds and 4 git commands to generate.