Fix: sessiond: rotation trigger leak
[lttng-tools.git] / src / bin / lttng-sessiond / rotation-thread.c
index 89a148a74c2bdd1393bb274afb4ae9f0f545caa1..e4811bd44bd957e854c8a0be1250632cd1a07854 100644 (file)
@@ -24,6 +24,9 @@
 #include <common/kernel-ctl/kernel-ctl.h>
 #include <lttng/notification/channel-internal.h>
 #include <lttng/rotate-internal.h>
+#include <lttng/location-internal.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/notification/notification-internal.h>
 
 #include "rotation-thread.h"
 #include "lttng-sessiond.h"
@@ -477,7 +480,6 @@ int check_session_rotation_pending(struct ltt_session *session,
 
        if (!session->quiet_rotation) {
                location = session_get_trace_archive_location(session);
-               /* Ownership of location is transferred. */
                ret = notification_thread_command_session_rotation_completed(
                                notification_thread_handle,
                                session->name,
@@ -485,6 +487,7 @@ int check_session_rotation_pending(struct ltt_session *session,
                                session->gid,
                                session->last_archived_chunk_id.value,
                                location);
+               lttng_trace_archive_location_put(location);
                if (ret != LTTNG_OK) {
                        ERR("Failed to notify notification thread of completed rotation for session %s",
                                        session->name);
@@ -582,8 +585,6 @@ int handle_job_queue(struct rotation_thread_handle *handle,
                session_lock_list();
                session = job->session;
                if (!session) {
-                       DBG("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
@@ -619,8 +620,7 @@ end:
 }
 
 static
-int handle_condition(const struct lttng_condition *condition,
-               const struct lttng_evaluation *evaluation,
+int handle_condition(const struct lttng_notification *notification,
                struct notification_thread_handle *notification_thread_handle)
 {
        int ret = 0;
@@ -630,6 +630,10 @@ int handle_condition(const struct lttng_condition *condition,
        enum lttng_evaluation_status evaluation_status;
        uint64_t consumed;
        struct ltt_session *session;
+       const struct lttng_condition *condition =
+                       lttng_notification_get_const_condition(notification);
+       const struct lttng_evaluation *evaluation =
+                       lttng_notification_get_const_evaluation(notification);
 
        condition_type = lttng_condition_get_type(condition);
 
@@ -658,14 +662,26 @@ int handle_condition(const struct lttng_condition *condition,
        session_lock_list();
        session = session_find_by_name(condition_session_name);
        if (!session) {
-               ret = -1;
-               session_unlock_list();
-               ERR("Session \"%s\" not found",
+               DBG("Failed to find session while handling notification: notification type = %s, session name = `%s`",
+                               lttng_condition_type_str(condition_type),
                                condition_session_name);
+               /*
+                * Not a fatal error: a session can be destroyed before we get
+                * the chance to handle the notification.
+                */
+               ret = 0;
+               session_unlock_list();
                goto end;
        }
        session_lock(session);
 
+       if (!lttng_trigger_is_equal(session->rotate_trigger,
+                       lttng_notification_get_const_trigger(notification))) {
+               /* Notification does not originate from our rotation trigger. */
+               ret = 0;
+               goto end_unlock;
+       }
+
        ret = unsubscribe_session_consumed_size_rotation(session,
                        notification_thread_handle);
        if (ret) {
@@ -708,8 +724,6 @@ int handle_notification_channel(int fd,
        bool notification_pending;
        struct lttng_notification *notification = NULL;
        enum lttng_notification_channel_status status;
-       const struct lttng_evaluation *notification_evaluation;
-       const struct lttng_condition *notification_condition;
 
        status = lttng_notification_channel_has_pending_notification(
                        rotate_notification_channel, &notification_pending);
@@ -747,10 +761,7 @@ int handle_notification_channel(int fd,
                goto end;
        }
 
-       notification_condition = lttng_notification_get_condition(notification);
-       notification_evaluation = lttng_notification_get_evaluation(notification);
-
-       ret = handle_condition(notification_condition, notification_evaluation,
+       ret = handle_condition(notification,
                        handle->notification_thread_handle);
 
 end:
This page took 0.023959 seconds and 4 git commands to generate.