Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / bin / lttng / commands / destroy.c
index 7cea7bf23303a6a2cadf48709f881f58c79964f5..0a5489304e1bcae9cc7c792a9b91887fc3f486ed 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -101,7 +91,7 @@ static int destroy_session(struct lttng_session *session)
                                        fflush(stdout);
                                }
 
-                               usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
+                               usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US);
                                _MSG(".");
                                fflush(stdout);
                        }
@@ -127,7 +117,7 @@ static int destroy_session(struct lttng_session *session)
 
        do {
                status = lttng_destruction_handle_wait_for_completion(handle,
-                               DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
+                               DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US / USEC_PER_MSEC);
                switch (status) {
                case LTTNG_DESTRUCTION_HANDLE_STATUS_TIMEOUT:
                        if (!printed_wait_msg) {
@@ -155,12 +145,16 @@ static int destroy_session(struct lttng_session *session)
                goto error;
        }
        if (ret_code != LTTNG_OK) {
-               ret = -LTTNG_OK;
+               ret = -ret_code;
                goto error;
        }
 
        status = lttng_destruction_handle_get_rotation_state(handle,
                        &rotation_state);
+       if (status != LTTNG_DESTRUCTION_HANDLE_STATUS_OK) {
+               ERR("Failed to get rotation state from destruction handle");
+               goto skip_wait_rotation;
+       }
        switch (rotation_state) {
        case LTTNG_ROTATION_STATE_NO_ROTATION:
                break;
@@ -192,6 +186,7 @@ static int destroy_session(struct lttng_session *session)
 skip_wait_rotation:
        MSG("%sSession \"%s\" destroyed", printed_wait_msg ? "\n" : "",
                        session->name);
+       printed_wait_msg = false;
 
        session_name = get_session_name_quiet();
        if (session_name && !strncmp(session->name, session_name, NAME_MAX)) {
@@ -208,6 +203,9 @@ skip_wait_rotation:
 
        ret = CMD_SUCCESS;
 error:
+       if (printed_wait_msg) {
+               MSG("");
+       }
        lttng_destruction_handle_destroy(handle);
        free(session_name);
        return ret;
@@ -220,23 +218,27 @@ error:
  */
 static int destroy_all_sessions(struct lttng_session *sessions, int count)
 {
-       int i, ret = CMD_SUCCESS;
+       int i;
+       bool error_occurred = false;
 
+       assert(count >= 0);
        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]);
+               int ret = destroy_session(&sessions[i]);
+
                if (ret < 0) {
-                       goto error;
+                       ERR("%s during the destruction of session \"%s\"",
+                                       lttng_strerror(ret),
+                                       sessions[i].name);
+                       /* Continue to next session. */
+                       error_occurred = true;
                }
        }
-error:
-       return ret;
+
+       return error_occurred ? CMD_ERROR : CMD_SUCCESS;
 }
 
 /*
@@ -342,8 +344,10 @@ int cmd_destroy(int argc, const char **argv)
                                command_ret = destroy_session(&sessions[i]);
                                if (command_ret) {
                                        success = 0;
+                                       ERR("%s during the destruction of session \"%s\"",
+                                                       lttng_strerror(command_ret),
+                                                       sessions[i].name);
                                }
-
                        }
                }
 
This page took 0.027598 seconds and 5 git commands to generate.