Improve error handling of lttng cli
[lttng-tools.git] / src / bin / lttng / commands / stop.c
index 0a942645db70b5b278e8af8c8b3f5e780d706ce2..f2ab453084f489cd38fe3cf2812a92278a05e296 100644 (file)
@@ -31,11 +31,13 @@ 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 +52,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "get it from the configuration directory (.lttng).\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -58,7 +61,7 @@ static void usage(FILE *ofp)
  */
 static int stop_tracing(void)
 {
-       int ret = CMD_SUCCESS;
+       int ret;
        char *session_name;
 
        if (opt_session_name == NULL) {
@@ -73,9 +76,12 @@ static int stop_tracing(void)
 
        ret = lttng_stop_tracing(session_name);
        if (ret < 0) {
+               /* Don't set ret so lttng can interpret the sessiond error. */
                goto free_name;
        }
 
+       ret = CMD_SUCCESS;
+
        MSG("Tracing stopped for session %s", session_name);
 
 free_name:
@@ -94,7 +100,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);
@@ -103,8 +109,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);
                        goto end;
                default:
                        usage(stderr);
@@ -118,5 +126,6 @@ int cmd_stop(int argc, const char **argv)
        ret = stop_tracing();
 
 end:
+       poptFreeContext(pc);
        return ret;
 }
This page took 0.023528 seconds and 4 git commands to generate.