+ ret = cmd_rotate_session(session, &rotation_return, false);
+ if (ret == LTTNG_OK) {
+ DBG("[rotation-thread] Scheduled time-based rotation successfully launched on session \"%s\"",
+ session->name);
+ } else {
+ /* Don't consider errors as fatal. */
+ DBG("[rotation-thread] Scheduled time-based rotation aborted for session %s: %s",
+ session->name, lttng_strerror(ret));
+ }
+ return 0;
+}
+
+static
+int run_job(struct rotation_thread_job *job, struct ltt_session *session,
+ struct notification_thread_handle *notification_thread_handle)
+{
+ int ret;
+
+ switch (job->type) {
+ case ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION:
+ ret = launch_session_rotation(session);
+ break;
+ case ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION:
+ ret = check_session_rotation_pending(session,
+ notification_thread_handle);
+ break;
+ default:
+ abort();
+ }
+ return ret;
+}
+
+static
+int handle_job_queue(struct rotation_thread_handle *handle,
+ struct rotation_thread *state,
+ struct rotation_thread_timer_queue *queue)
+{
+ int ret = 0;
+
+ for (;;) {
+ struct ltt_session *session;
+ struct rotation_thread_job *job;
+
+ /* Take the queue lock only to pop an element from the list. */
+ pthread_mutex_lock(&queue->lock);
+ if (cds_list_empty(&queue->list)) {
+ pthread_mutex_unlock(&queue->lock);
+ break;
+ }
+ job = cds_list_first_entry(&queue->list,
+ typeof(*job), head);
+ cds_list_del(&job->head);
+ pthread_mutex_unlock(&queue->lock);
+
+ session_lock_list();
+ session = job->session;
+ if (!session) {
+ DBG("[rotation-thread] Session \"%s\" not found",
+ session->name);
+ /*
+ * This is a non-fatal error, and we cannot report it to
+ * the user (timer), so just print the error and
+ * continue the processing.
+ *
+ * While the timer thread will purge pending signals for
+ * a session on the session's destruction, it is
+ * possible for a job targeting that session to have
+ * already been queued before it was destroyed.
+ */
+ free(job);
+ session_put(session);
+ session_unlock_list();
+ continue;