X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fnotification-thread-events.cpp;h=8065cd7323b20f8c9ca8bfa137d88ff44d9c5810;hb=d4333eb996dec315fb721074c2cf49adee04363b;hp=58a38cce191d7b720861d14e8aa96161cfc7a008;hpb=56047f5a23df5c2c583a102b8015bbec5a7da9f1;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/notification-thread-events.cpp b/src/bin/lttng-sessiond/notification-thread-events.cpp index 58a38cce1..8065cd732 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.cpp +++ b/src/bin/lttng-sessiond/notification-thread-events.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -2502,8 +2503,6 @@ end: static bool is_trigger_action_notify(const struct lttng_trigger *trigger) { bool is_notify = false; - unsigned int i, count; - enum lttng_action_status action_status; const struct lttng_action *action = lttng_trigger_get_const_action(trigger); enum lttng_action_type action_type; @@ -2516,14 +2515,8 @@ static bool is_trigger_action_notify(const struct lttng_trigger *trigger) goto end; } - action_status = lttng_action_list_get_count(action, &count); - LTTNG_ASSERT(action_status == LTTNG_ACTION_STATUS_OK); - - for (i = 0; i < count; i++) { - const struct lttng_action *inner_action = lttng_action_list_get_at_index(action, i); - - action_type = lttng_action_get_type(inner_action); - if (action_type == LTTNG_ACTION_TYPE_NOTIFY) { + for (auto inner_action : lttng::ctl::const_action_list_view(action)) { + if (lttng_action_get_type(inner_action) == LTTNG_ACTION_TYPE_NOTIFY) { is_notify = true; goto end; } @@ -3158,27 +3151,27 @@ end: return 0; } -static int pop_cmd_queue(struct notification_thread_handle *handle, - struct notification_thread_command **cmd) +static notification_thread_command *pop_cmd_queue(notification_thread_handle *handle) { - int ret; - uint64_t counter; + lttng::pthread::lock_guard queue_lock(handle->cmd_queue.lock); - 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; + uint64_t counter; + const auto read_ret = lttng_read(handle->cmd_queue.event_fd, &counter, sizeof(counter)); + if (read_ret != sizeof(counter)) { + if (read_ret < 0) { + LTTNG_THROW_POSIX("Failed to read counter value from event_fd", errno); + } else { + LTTNG_THROW_ERROR(lttng::format( + "Failed to read counter value from event_fd because of a truncated read: ret={}, expected read size={}", + read_ret, + sizeof(counter))); + } } - *cmd = cds_list_first_entry( + auto command = 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; + cds_list_del(&((command)->cmd_list_node)); + return command; } /* Returns 0 on success, 1 on exit requested, negative value on error. */ @@ -3186,10 +3179,12 @@ int handle_notification_thread_command(struct notification_thread_handle *handle struct notification_thread_state *state) { int ret; - struct notification_thread_command *cmd; + struct notification_thread_command *cmd = nullptr; - ret = pop_cmd_queue(handle, &cmd); - if (ret) { + try { + cmd = pop_cmd_queue(handle); + } catch (const std::exception& ex) { + ERR("Failed to get next notification thread command: %s", ex.what()); goto error; } @@ -3319,21 +3314,26 @@ int handle_notification_thread_command(struct notification_thread_handle *handle if (ret) { goto error_unlock; } + end: - if (cmd->is_async) { - free(cmd); - cmd = nullptr; - } else { - lttng_waiter_wake_up(&cmd->reply_waiter); + if (cmd) { + if (cmd->is_async) { + delete cmd; + cmd = nullptr; + } else { + cmd->command_completed_waker->wake(); + } } + return ret; + error_unlock: /* Wake-up and return a fatal error to the calling thread. */ - lttng_waiter_wake_up(&cmd->reply_waiter); cmd->reply_code = LTTNG_ERR_FATAL; + error: - /* Indicate a fatal error to the caller. */ - return -1; + ret = -1; + goto end; } static int socket_set_non_blocking(int socket)