Fix: run_command_wait() handle partial write
[lttng-tools.git] / src / bin / lttng-sessiond / notification-thread-commands.c
index 5483a317f60c28bedd8a5ecf96ac87768d9ed52d..dc782e2934f27a4b6bed48249223a2b55aab5e4a 100644 (file)
@@ -20,7 +20,6 @@
 #include "notification-thread.h"
 #include "notification-thread-commands.h"
 #include <common/error.h>
-#include <common/futex.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <inttypes.h>
@@ -30,6 +29,7 @@ void init_notification_thread_command(struct notification_thread_command *cmd)
 {
        memset(cmd, 0, sizeof(*cmd));
        CDS_INIT_LIST_HEAD(&cmd->cmd_list_node);
+       lttng_waiter_init(&cmd->reply_waiter);
 }
 
 static
@@ -39,16 +39,14 @@ int run_command_wait(struct notification_thread_handle *handle,
        int ret;
        uint64_t notification_counter = 1;
 
-       futex_nto1_prepare(&cmd->reply_futex);
-
        pthread_mutex_lock(&handle->cmd_queue.lock);
        /* Add to queue. */
        cds_list_add_tail(&cmd->cmd_list_node,
                        &handle->cmd_queue.list);
        /* Wake-up thread. */
-       ret = write(handle->cmd_queue.event_fd,
+       ret = lttng_write(lttng_pipe_get_writefd(handle->cmd_queue.event_pipe),
                        &notification_counter, sizeof(notification_counter));
-       if (ret < 0) {
+       if (ret != sizeof(notification_counter)) {
                PERROR("write to notification thread's queue event fd");
                /*
                 * Remove the command from the list so the notification
@@ -59,7 +57,7 @@ int run_command_wait(struct notification_thread_handle *handle,
        }
        pthread_mutex_unlock(&handle->cmd_queue.lock);
 
-       futex_nto1_wait(&cmd->reply_futex);
+       lttng_waiter_wait(&cmd->reply_waiter);
        return 0;
 error_unlock_queue:
        pthread_mutex_unlock(&handle->cmd_queue.lock);
This page took 0.024815 seconds and 4 git commands to generate.