+ if (opt_no_wait) {
+ goto skip_wait_rotation;
+ }
+
+ do {
+ status = lttng_destruction_handle_wait_for_completion(
+ handle, DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US /
+ USEC_PER_MSEC);
+ switch (status) {
+ case LTTNG_DESTRUCTION_HANDLE_STATUS_TIMEOUT:
+ if (!printed_destroy_msg) {
+ _MSG("Destroying session %s", session->name);
+ newline_needed = true;
+ printed_destroy_msg = true;
+ }
+ _MSG(".");
+ fflush(stdout);
+ break;
+ case LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED:
+ break;
+ default:
+ ERR("%sFailed to wait for the completion of the destruction of session \"%s\"",
+ newline_needed ? "\n" : "",
+ session->name);
+ newline_needed = false;
+ ret = -1;
+ goto error;
+ }
+ } while (status == LTTNG_DESTRUCTION_HANDLE_STATUS_TIMEOUT);
+
+ status = lttng_destruction_handle_get_result(handle, &ret_code);
+ if (status != LTTNG_DESTRUCTION_HANDLE_STATUS_OK) {
+ ERR("%sFailed to get the result of session destruction",
+ newline_needed ? "\n" : "");
+ ret = -1;
+ newline_needed = false;
+ goto error;
+ }
+ if (ret_code != 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("%sFailed to get rotation state from destruction handle",
+ newline_needed ? "\n" : "");
+ newline_needed = false;
+ goto skip_wait_rotation;
+ }
+
+ switch (rotation_state) {
+ case LTTNG_ROTATION_STATE_NO_ROTATION:
+ break;
+ case LTTNG_ROTATION_STATE_COMPLETED:
+ {
+ const struct lttng_trace_archive_location *location;
+
+ status = lttng_destruction_handle_get_archive_location(
+ handle, &location);
+ if (status == LTTNG_DESTRUCTION_HANDLE_STATUS_OK) {
+ ret = print_trace_archive_location(
+ location, session->name);
+ if (ret) {
+ ERR("%sFailed to print the location of trace archive",
+ newline_needed ? "\n" : "");
+ newline_needed = false;
+ goto skip_wait_rotation;
+ }
+ break;
+ }
+ /* fall-through. */
+ }
+ default:
+ ERR("%sFailed to get the location of the rotation performed during the session's destruction",
+ newline_needed ? "\n" : "");
+ newline_needed = false;
+ goto skip_wait_rotation;
+ }
+skip_wait_rotation:
+ MSG("%sSession %s destroyed", newline_needed ? "\n" : "",
+ session->name);
+ newline_needed = false;
+ if (stats_str) {
+ MSG("%s", stats_str);
+ }