- timeinfo = localtime(&session->last_chunk_start_ts);
- if (!timeinfo) {
- ERR("Failed to retrieve local time while renaming completed chunk");
- ret = -1;
- goto end;
- }
-
- strf_ret = strftime(start_time, sizeof(start_time),
- "%Y%m%d-%H%M%S", timeinfo);
- if (strf_ret == 0) {
- ERR("Failed to format timestamp while renaming completed session chunk");
- ret = -1;
- goto end;
- }
-
- /*
- * 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.
- */
- ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64,
- session->rotation_chunk.current_rotate_path,
- start_time,
- datetime, session->rotate_count);
- if (ret < 0 || ret >= sizeof(new_path)) {
- ERR("Failed to format new chunk path while renaming session \"%s\"'s first chunk",
- session->name);
- ret = -1;
- goto end;
- }
-
- if (session->kernel_session) {
- ret = rename_first_chunk(session,
- session->kernel_session->consumer,
- new_path);
- if (ret) {
- ERR("Failed to rename kernel session trace folder to %s", new_path);
- /*
- * This is not a fatal error for the rotation
- * thread, we just need to inform the client
- * that a problem occurred with the rotation.
- * Returning 0, same for the other errors
- * below.
- */
- ret = 0;
- goto error;
- }
- }
- if (session->ust_session) {
- ret = rename_first_chunk(session,
- session->ust_session->consumer,
- new_path);
- if (ret) {
- ERR("Failed to rename userspace session trace folder to %s", new_path);
- ret = 0;
- goto error;
- }
- }
- } else {
- /*
- * After the first rotation, all the trace data is already in
- * its own chunk folder, we just need to append the suffix.
- */
- /* Recreate the session->rotation_chunk.current_rotate_path */
- timeinfo = localtime(&session->last_chunk_start_ts);
- if (!timeinfo) {
- ERR("Failed to retrieve local time while renaming completed chunk");
- ret = -1;
- goto end;
- }
- strf_ret = strftime(start_datetime, sizeof(start_datetime), "%Y%m%d-%H%M%S", timeinfo);
- if (!strf_ret) {
- ERR("Failed to format timestamp while renaming completed session chunk");
- ret = -1;
- goto end;
- }
- ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64,
- session_get_base_path(session),
- start_datetime,
- datetime, session->rotate_count);
- if (ret < 0 || ret >= sizeof(new_path)) {
- ERR("Failed to format new chunk path while renaming chunk of session \"%s\"",
- session->name);
- ret = -1;
- goto error;
- }
- ret = session_rename_chunk(session,
- session->rotation_chunk.current_rotate_path,
- new_path);
- if (ret) {
- ERR("Failed to rename session trace folder from %s to %s",
- session->rotation_chunk.current_rotate_path,
- new_path);
- ret = 0;
- goto error;
- }