Fix: Revert of 814b4934e2604a419bcb8eec57c0450dbb47e2c3
[lttng-tools.git] / src / bin / lttng-sessiond / notification-thread-events.c
index 1093784113cd4e2b35cc5093ab3dd7d5b5bc6b69..a9aad24ac4b6aac4c23ba93a3b9f4d6352fb3df8 100644 (file)
@@ -2039,7 +2039,7 @@ int handle_notification_thread_command_add_tracer_event_source(
                        lttng_domain_type_str(domain_type));
 
        /* Adding the read side pipe to the event poll. */
-       ret = lttng_poll_add(&state->events, tracer_event_source_fd, LPOLLIN | LPOLLERR);
+       ret = lttng_poll_add(&state->events, tracer_event_source_fd, LPOLLPRI | LPOLLIN | LPOLLERR);
        if (ret < 0) {
                ERR("Failed to add tracer event source to poll set: tracer_event_source_fd = %d, domain = '%s'",
                                tracer_event_source_fd,
@@ -2125,7 +2125,7 @@ find_tracer_event_source_element(struct notification_thread_state *state,
 
        source_element = NULL;
 end:
-       return NULL;
+       return source_element;
 }
 
 static
@@ -2153,6 +2153,12 @@ int remove_tracer_event_source_from_pollset(
 
        source_element->is_fd_in_poll_set = false;
 
+       /*
+        * Force the notification thread to restart the poll() loop to ensure
+        * that any events from the removed fd are removed.
+        */
+       state->restart_poll = true;
+
        ret = drain_event_notifier_notification_pipe(state, source_element->fd,
                        source_element->domain);
        if (ret) {
@@ -3103,28 +3109,55 @@ end:
        return 0;
 }
 
+static
+int pop_cmd_queue(struct notification_thread_handle *handle,
+               struct notification_thread_command **cmd)
+{
+       int ret;
+       uint64_t counter;
+
+       pthread_mutex_lock(&handle->cmd_queue.lock);
+       ret = lttng_read(handle->cmd_queue.event_fd, &counter, sizeof(counter));
+       if (ret != sizeof(counter)) {
+               ret = -1;
+               goto error_unlock;
+       }
+
+       /* Simulate behaviour of EFD_SEMAPHORE for older kernels. */
+       counter -= 1;
+       if (counter != 0) {
+               ret = lttng_write(handle->cmd_queue.event_fd, &counter,
+                               sizeof(counter));
+               if (ret != sizeof(counter)) {
+                       PERROR("Failed to write back to event_fd for EFD_SEMAPHORE emulation");
+                       ret = -1;
+                       goto error_unlock;
+               }
+       }
+
+       *cmd = cds_list_first_entry(&handle->cmd_queue.list,
+                       struct notification_thread_command, cmd_list_node);
+       cds_list_del(&((*cmd)->cmd_list_node));
+       ret = 0;
+
+error_unlock:
+       pthread_mutex_unlock(&handle->cmd_queue.lock);
+       return ret;
+}
+
 /* Returns 0 on success, 1 on exit requested, negative value on error. */
 int handle_notification_thread_command(
                struct notification_thread_handle *handle,
                struct notification_thread_state *state)
 {
        int ret;
-       uint64_t counter;
        struct notification_thread_command *cmd;
 
-       /* Read the event pipe to put it back into a quiescent state. */
-       ret = lttng_read(lttng_pipe_get_readfd(handle->cmd_queue.event_pipe), &counter,
-                       sizeof(counter));
-       if (ret != sizeof(counter)) {
+       ret = pop_cmd_queue(handle, &cmd);
+       if (ret) {
                goto error;
        }
 
-       pthread_mutex_lock(&handle->cmd_queue.lock);
-       cmd = cds_list_first_entry(&handle->cmd_queue.list,
-                       struct notification_thread_command, cmd_list_node);
-       cds_list_del(&cmd->cmd_list_node);
-       pthread_mutex_unlock(&handle->cmd_queue.lock);
-
        DBG("Received `%s` command",
                        notification_command_type_str(cmd->type));
        switch (cmd->type) {
@@ -4421,7 +4454,8 @@ int notification_client_list_send_evaluation(
                         * Notifications resulting from an hidden trigger are
                         * only sent to the session daemon.
                         */
-                       continue;
+                       DBG("Skipping client as the trigger is hidden and the client is not the session daemon");
+                       goto skip_client;
                }
 
                if (source_object_creds) {
This page took 0.025504 seconds and 4 git commands to generate.