+ bool session_was_already_stopped;
+ enum lttng_error_code ret_code;
+ struct lttng_destruction_handle *handle = NULL;
+ enum lttng_destruction_handle_status status;
+ bool newline_needed = false, printed_destroy_msg = false;
+ enum lttng_rotation_state rotation_state;
+ char *stats_str = NULL;
+
+ ret = lttng_stop_tracing_no_wait(session->name);
+ if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
+ ERR("%s", lttng_strerror(ret));
+ }
+
+ session_was_already_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_destroy_msg) {
+ _MSG("Destroying session %s",
+ session->name);
+ newline_needed = true;
+ printed_destroy_msg = true;
+ fflush(stdout);
+ }
+
+ usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US);
+ _MSG(".");
+ fflush(stdout);
+ }
+ } while (ret != 0);
+ }
+
+ if (!session_was_already_stopped) {
+ /*
+ * Don't print the event and packet loss warnings since the user
+ * already saw them when stopping the trace.
+ */
+ ret = get_session_stats_str(session->name, &stats_str);
+ if (ret < 0) {
+ goto error;
+ }
+ }