Fix: destroy session removes the default config file
[lttng-tools.git] / src / bin / lttng / commands / destroy.c
index fea96f1757907178ea8e89b7ee6a21bdd18c27be..03f10dac9666473043b1061530b5efa9c21e1ae2 100644 (file)
@@ -27,6 +27,7 @@
 #include "../command.h"
 
 #include <common/sessiond-comm/sessiond-comm.h>
+#include <common/utils.h>
 
 static char *opt_session_name;
 static int opt_destroy_all;
@@ -70,23 +71,31 @@ static void usage(FILE *ofp)
 static int destroy_session(const char *session_name)
 {
        int ret;
+       char *default_session_name = NULL;
 
        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:
+                       ERR("%s", lttng_strerror(ret));
                        break;
                }
                goto error;
        }
 
        MSG("Session %s destroyed", session_name);
-       config_destroy_default();
+
+       default_session_name = get_session_name_quiet();
+       if (default_session_name &&
+               !strncmp(session_name, session_name, NAME_MAX)) {
+               config_destroy_default();
+       }
        ret = CMD_SUCCESS;
 error:
+       free(default_session_name);
        return ret;
 }
 
@@ -103,7 +112,11 @@ static int destroy_all_sessions()
        count = lttng_list_sessions(&sessions);
        if (count == 0) {
                MSG("No session found, nothing to do.");
+       } else if (count < 0) {
+               ERR("%s", lttng_strerror(ret));
+               goto error;
        }
+
        for (i = 0; i < count; i++) {
                ret = destroy_session(sessions[i].name);
                if (ret < 0) {
This page took 0.024881 seconds and 4 git commands to generate.