Add lttng-error.h containing every API err. code
[lttng-tools.git] / src / bin / lttng / commands / destroy.c
index 5b69cb5d9b45e54f7f7877f859bde66eb5febd54..f26da066977da67bc0fe945d55a7162cfc08196d 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <common/sessiond-comm/sessiond-comm.h>
 
+static char *opt_session_name;
 static int opt_destroy_all;
 
 enum {
@@ -48,11 +49,12 @@ static struct poptOption long_options[] = {
  */
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "usage: lttng destroy [options] [NAME]\n");
+       fprintf(ofp, "usage: lttng destroy [NAME] [OPTIONS]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Where NAME is an optional session name. If not specified, lttng will\n");
        fprintf(ofp, "get it from the configuration directory (.lttng).\n");
        fprintf(ofp, "\n");
+       fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help           Show this help\n");
        fprintf(ofp, "  -a, --all            Destroy all sessions\n");
        fprintf(ofp, "      --list-options   Simple listing of options\n");
@@ -72,7 +74,7 @@ static int destroy_session(const char *session_name)
        ret = lttng_destroy_session(session_name);
        if (ret < 0) {
                switch (-ret) {
-               case LTTCOMM_SESS_NOT_FOUND:
+               case LTTNG_ERR_SESS_NOT_FOUND:
                        WARN("Session name %s not found", session_name);
                        break;
                default:
@@ -112,21 +114,6 @@ error:
        return ret;
 }
 
-/*
- * get_default_session_name
- *
- * Returns the default sessions name, if any
- */
-static int get_default_session_name(char **name)
-{
-       char *session_name = get_session_name();
-       if (session_name == NULL) {
-               return CMD_ERROR;
-       }
-       *name = session_name;
-       return CMD_SUCCESS;
-}
-
 /*
  * The 'destroy <options>' first level command
  */
@@ -156,28 +143,32 @@ int cmd_destroy(int argc, const char **argv)
                goto end;
        }
 
-       session_name = (char *) poptGetArg(pc);
-
-       /*
-        * ignore session name in case all
-        * sessions are to be destroyed
-        */
+       /* Ignore session name in case all sessions are to be destroyed */
        if (opt_destroy_all) {
                ret = destroy_all_sessions();
                goto end;
        }
-       if (session_name == NULL) {
-               ret = get_default_session_name(&session_name);
-               if (ret < 0 || session_name == NULL) {
+
+       opt_session_name = (char *) poptGetArg(pc);
+
+       if (opt_session_name == NULL) {
+               /* No session name specified, lookup default */
+               session_name = get_session_name();
+               if (session_name == NULL) {
+                       ret = CMD_ERROR;
                        goto end;
                }
+       } else {
+               session_name = opt_session_name;
        }
+
        ret = destroy_session(session_name);
 
 end:
-       poptFreeContext(pc);
-       if (session_name != NULL) {
+       if (opt_session_name == NULL) {
                free(session_name);
        }
+
+       poptFreeContext(pc);
        return ret;
 }
This page took 0.025882 seconds and 4 git commands to generate.