+ ret = lttng_stop_tracing_no_wait(session->name);
+ if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
+ ERR("%s", lttng_strerror(ret));
+ }
+ session_was_stopped = ret == -LTTNG_ERR_TRACE_ALREADY_STOPPED;
+ if (!opt_no_wait) {
+ do {
+ ret = lttng_data_pending(session->name);
+ if (ret < 0) {
+ /* Return the data available call error. */
+ goto error;
+ }
+
+ /*
+ * Data sleep time before retrying (in usec). Don't sleep if the call
+ * returned value indicates availability.
+ */
+ if (ret) {
+ if (!printed_wait_msg) {
+ _MSG("Waiting for destruction of session \"%s\"",
+ session->name);
+ printed_wait_msg = true;
+ fflush(stdout);
+ }
+
+ usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US);
+ _MSG(".");
+ fflush(stdout);
+ }
+ } while (ret != 0);
+ }
+ if (!session_was_stopped) {
+ /*
+ * Don't print the event and packet loss warnings since the user
+ * already saw them when stopping the trace.
+ */
+ print_session_stats(session->name);
+ }
+
+ ret_code = lttng_destroy_session_ext(session->name, &handle);
+ if (ret_code != LTTNG_OK) {
+ ret = -ret_code;
+ goto error;
+ }
+
+ 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_wait_msg) {
+ _MSG("Waiting for destruction of session \"%s\"",
+ session->name);
+ printed_wait_msg = true;
+ }
+ _MSG(".");
+ fflush(stdout);
+ break;
+ case LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED:
+ break;
+ default:
+ ERR("Failed to wait for the completion of the destruction of session \"%s\"",
+ session->name);
+ ret = -1;