+ timeinfo = localtime(&session->last_chunk_start_ts);
+ strftime(start_time, sizeof(start_time), "%Y%m%d-%H%M%S", timeinfo);
+
+ /*
+ * On the first rotation, the current_rotate_path is the
+ * session_root_path, so we need to create the chunk folder
+ * and move the domain-specific folders inside it.
+ */
+ snprintf(new_path, PATH_MAX, "%s/%s-%s-%" PRIu64,
+ session->rotation_chunk.current_rotate_path,
+ start_time,
+ datetime, session->rotate_count);
+
+ if (session->kernel_session) {
+ fprintf(stderr, "rename %s/kernel to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+ ret = rename_first_chunk(session,
+ session->kernel_session->consumer,
+ new_path);
+ if (ret) {
+ ERR("Rename kernel session");
+ ret = -1;
+ goto end;
+ }
+ }
+ if (session->ust_session) {
+ fprintf(stderr, "rename %s/kernel to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+ ret = rename_first_chunk(session,
+ session->ust_session->consumer,
+ new_path);
+ if (ret) {
+ ERR("Rename ust session");
+ ret = -1;
+ goto end;
+ }
+ }
+ } else {
+ /*
+ * After the first rotation, all the trace data is already in
+ * its own chunk folder, we just need to append the suffix.
+ */
+ snprintf(new_path, PATH_MAX, "%s%s-%" PRIu64,
+ session->rotation_chunk.current_rotate_path,
+ datetime, session->rotate_count);
+
+ fprintf(stderr, "rename %s to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+
+ ret = session_rename_chunk(session,
+ session->rotation_chunk.current_rotate_path,
+ new_path, 0);
+ if (ret) {
+ ERR("Session rename");
+ ret = -1;
+ goto end;
+ }