- /*
- * The rename of the current chunk is performed at stop, but if we rotated
- * the session after the previous stop command, we need to rename the
- * new (and empty) chunk that was started in between.
- */
- if (session->rotated_after_last_stop) {
- rename_active_chunk(session);
- }
-
- /* Clean kernel session teardown */
- kernel_destroy_session(ksess);
-
- /* UST session teardown */
- if (usess) {
- /* Close any relayd session */
- consumer_output_send_destroy_relayd(usess->consumer);
-
- /* Destroy every UST application related to this session. */
- ret = ust_app_destroy_trace_all(usess);
- if (ret) {
- ERR("Error in ust_app_destroy_trace_all");
+ if (session->current_archive_id != 0) {
+ if (!session->rotated_after_last_stop) {
+ ret = cmd_rotate_session(session, NULL);
+ if (ret != LTTNG_OK) {
+ ERR("Failed to perform an implicit rotation as part of the rotation: %s", lttng_strerror(-ret));
+ }
+ } else {
+ /*
+ * Rename the active chunk to ensure it has a name
+ * of the form ts_begin-ts_end-id.
+ *
+ * Note that no trace data has been produced since
+ * the last rotation; the directory should be
+ * removed.
+ */
+ ret = rename_active_chunk(session);
+ if (ret) {
+ ERR("Failed to rename active chunk during the destruction of session \"%s\"",
+ session->name);
+ }