Fix: sessiond: ODR violation results in memory corruption
[lttng-tools.git] / src / bin / lttng-sessiond / action-executor.cpp
index f43716c63986673377890c8a635f25c149a4f7d7..23a99a1acbbb7ec94458ad79a5dc7d9a85ba68ee 100644 (file)
 #define THREAD_NAME "Action Executor"
 #define MAX_QUEUED_WORK_COUNT 8192
 
+struct action_executor {
+       struct lttng_thread *thread;
+       struct notification_thread_handle *notification_thread_handle;
+       struct {
+               uint64_t pending_count;
+               struct cds_list_head list;
+               pthread_cond_t cond;
+               pthread_mutex_t lock;
+       } work;
+       bool should_quit;
+       uint64_t next_work_item_id;
+};
+
+namespace {
 /*
  * A work item is composed of a dynamic array of sub-items which
  * represent a flattened, and augmented, version of a trigger's actions.
@@ -69,7 +83,6 @@
  * trigger object at the moment of execution, if the trigger is found to be
  * unregistered, the execution is skipped.
  */
-
 struct action_work_item {
        uint64_t id;
 
@@ -94,19 +107,8 @@ struct action_work_subitem {
                LTTNG_OPTIONAL(uint64_t) session_id;
        } context;
 };
+} /* namespace */
 
-struct action_executor {
-       struct lttng_thread *thread;
-       struct notification_thread_handle *notification_thread_handle;
-       struct {
-               uint64_t pending_count;
-               struct cds_list_head list;
-               pthread_cond_t cond;
-               pthread_mutex_t lock;
-       } work;
-       bool should_quit;
-       uint64_t next_work_item_id;
-};
 
 /*
  * Only return non-zero on a fatal error that should shut down the action
@@ -233,6 +235,15 @@ static int client_handle_transmission_status(
        case CLIENT_TRANSMISSION_STATUS_COMPLETE:
                DBG("Successfully sent full notification to client, client_id = %" PRIu64,
                                client->id);
+               /*
+                * There is no need to wake the (e)poll thread. If it was waiting for
+                * "out" events on the client's socket, it will see that no payload
+                * in queued and will unsubscribe from that event.
+                *
+                * In the other cases, we have to wake the the (e)poll thread to either
+                * handle the error on the client or to get it to monitor the client "out"
+                * events.
+                */
                update_communication = false;
                break;
        case CLIENT_TRANSMISSION_STATUS_QUEUED:
@@ -821,7 +832,7 @@ static void clean_up_action_executor_thread(void *_data)
 struct action_executor *action_executor_create(
                struct notification_thread_handle *handle)
 {
-       struct action_executor *executor = (action_executor *) zmalloc(sizeof(*executor));
+       struct action_executor *executor = zmalloc<action_executor>();
 
        if (!executor) {
                goto end;
@@ -893,7 +904,7 @@ enum action_executor_status action_executor_enqueue_trigger(
                goto error_unlock;
        }
 
-       work_item = (action_work_item *) zmalloc(sizeof(*work_item));
+       work_item = zmalloc<action_work_item>();
        if (!work_item) {
                PERROR("Failed to allocate action executor work item: trigger name = `%s`",
                                get_trigger_name(trigger));
This page took 0.023924 seconds and 4 git commands to generate.