Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / action-executor.cpp
index 87e94bd82b7ad26e9db0fd99338d47576da07740..3fbb87f431858b6232b412cfed2ea292e6305214 100644 (file)
@@ -16,6 +16,7 @@
 #include <common/dynamic-array.hpp>
 #include <common/macros.hpp>
 #include <common/optional.hpp>
+#include <common/urcu.hpp>
 
 #include <lttng/action/action-internal.hpp>
 #include <lttng/action/list-internal.hpp>
@@ -273,7 +274,7 @@ static int action_executor_notify_handler(struct action_executor *executor,
                work_item->client_list,
                work_item->trigger,
                work_item->evaluation,
-               work_item->object_creds.is_set ? &(work_item->object_creds.value) : NULL,
+               work_item->object_creds.is_set ? &(work_item->object_creds.value) : nullptr,
                client_handle_transmission_status,
                executor);
 }
@@ -290,6 +291,8 @@ static int action_executor_start_session_handler(struct action_executor *executo
        enum lttng_error_code cmd_ret;
        struct lttng_action *action = item->action;
 
+       lttng::urcu::read_lock_guard read_lock;
+
        action_status = lttng_action_start_session_get_session_name(action, &session_name);
        if (action_status != LTTNG_ACTION_STATUS_OK) {
                ERR("Failed to get session name from `%s` action", get_action_name(action));
@@ -311,7 +314,6 @@ static int action_executor_start_session_handler(struct action_executor *executo
        }
 
        session_lock_list();
-       rcu_read_lock();
        session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id));
        if (!session) {
                DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
@@ -362,7 +364,6 @@ error_unlock_session:
        session_unlock(session);
        session_put(session);
 error_unlock_list:
-       rcu_read_unlock();
        session_unlock_list();
 end:
        return ret;
@@ -380,6 +381,8 @@ static int action_executor_stop_session_handler(struct action_executor *executor
        enum lttng_error_code cmd_ret;
        struct lttng_action *action = item->action;
 
+       lttng::urcu::read_lock_guard read_lock;
+
        action_status = lttng_action_stop_session_get_session_name(action, &session_name);
        if (action_status != LTTNG_ACTION_STATUS_OK) {
                ERR("Failed to get session name from `%s` action", get_action_name(action));
@@ -401,7 +404,6 @@ static int action_executor_stop_session_handler(struct action_executor *executor
        }
 
        session_lock_list();
-       rcu_read_lock();
        session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id));
        if (!session) {
                DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
@@ -452,7 +454,6 @@ error_unlock_session:
        session_unlock(session);
        session_put(session);
 error_unlock_list:
-       rcu_read_unlock();
        session_unlock_list();
 end:
        return ret;
@@ -470,6 +471,8 @@ static int action_executor_rotate_session_handler(struct action_executor *execut
        enum lttng_error_code cmd_ret;
        struct lttng_action *action = item->action;
 
+       lttng::urcu::read_lock_guard read_lock;
+
        action_status = lttng_action_rotate_session_get_session_name(action, &session_name);
        if (action_status != LTTNG_ACTION_STATUS_OK) {
                ERR("Failed to get session name from `%s` action", get_action_name(action));
@@ -491,7 +494,6 @@ static int action_executor_rotate_session_handler(struct action_executor *execut
        }
 
        session_lock_list();
-       rcu_read_lock();
        session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id));
        if (!session) {
                DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
@@ -518,7 +520,7 @@ static int action_executor_rotate_session_handler(struct action_executor *execut
        }
 
        cmd_ret = (lttng_error_code) cmd_rotate_session(
-               session, NULL, false, LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
+               session, nullptr, false, LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
        switch (cmd_ret) {
        case LTTNG_OK:
                DBG("Successfully started rotation of session `%s` on behalf of trigger `%s`",
@@ -550,7 +552,6 @@ error_unlock_session:
        session_unlock(session);
        session_put(session);
 error_unlock_list:
-       rcu_read_unlock();
        session_unlock_list();
 end:
        return ret;
@@ -572,6 +573,8 @@ static int action_executor_snapshot_session_handler(struct action_executor *exec
 
        default_snapshot_output.max_size = UINT64_MAX;
 
+       lttng::urcu::read_lock_guard read_lock;
+
        /*
         * Validate if, at the moment the action was queued, the target session
         * existed. If not, skip the action altogether.
@@ -599,7 +602,6 @@ static int action_executor_snapshot_session_handler(struct action_executor *exec
        }
 
        session_lock_list();
-       rcu_read_lock();
        session = session_find_by_id(LTTNG_OPTIONAL_GET(item->context.session_id));
        if (!session) {
                DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
@@ -645,7 +647,6 @@ error_unlock_session:
        session_unlock(session);
        session_put(session);
 error_unlock_list:
-       rcu_read_unlock();
        session_unlock_list();
 end:
        return ret;
@@ -769,7 +770,7 @@ static void *action_executor_thread(void *_data)
                /* Execute item only if a trigger is registered. */
                lttng_trigger_lock(work_item->trigger);
                if (!lttng_trigger_is_registered(work_item->trigger)) {
-                       const char *trigger_name = NULL;
+                       const char *trigger_name = nullptr;
                        uid_t trigger_owner_uid;
                        enum lttng_trigger_status trigger_status;
 
@@ -813,7 +814,7 @@ static void *action_executor_thread(void *_data)
        rcu_unregister_thread();
        health_unregister(the_health_sessiond);
 
-       return NULL;
+       return nullptr;
 }
 
 static bool shutdown_action_executor_thread(void *_data)
@@ -847,8 +848,8 @@ struct action_executor *action_executor_create(struct notification_thread_handle
        }
 
        CDS_INIT_LIST_HEAD(&executor->work.list);
-       pthread_cond_init(&executor->work.cond, NULL);
-       pthread_mutex_init(&executor->work.lock, NULL);
+       pthread_cond_init(&executor->work.cond, nullptr);
+       pthread_mutex_init(&executor->work.lock, nullptr);
        executor->notification_thread_handle = handle;
 
        executor->thread = lttng_thread_create(THREAD_NAME,
@@ -933,7 +934,7 @@ action_executor_enqueue_trigger(struct action_executor *executor,
 
        /* Ownership transferred to the work item. */
        work_item->evaluation = evaluation;
-       evaluation = NULL;
+       evaluation = nullptr;
 
        work_item->client_list = client_list;
        work_item->object_creds.is_set = !!object_creds;
@@ -978,10 +979,10 @@ static int add_action_to_subitem_array(struct lttng_action *action,
 {
        int ret = 0;
        enum lttng_action_type type = lttng_action_get_type(action);
-       const char *session_name = NULL;
+       const char *session_name = nullptr;
        enum lttng_action_status status;
        struct action_work_subitem subitem = {
-               .action = NULL,
+               .action = nullptr,
                .context = {
                        .session_id = LTTNG_OPTIONAL_INIT_UNSET,
                },
@@ -991,16 +992,9 @@ static int add_action_to_subitem_array(struct lttng_action *action,
        LTTNG_ASSERT(subitems);
 
        if (type == LTTNG_ACTION_TYPE_LIST) {
-               unsigned int count, i;
-
-               status = lttng_action_list_get_count(action, &count);
-               LTTNG_ASSERT(status == LTTNG_ACTION_STATUS_OK);
-
-               for (i = 0; i < count; i++) {
-                       struct lttng_action *inner_action = NULL;
-
-                       inner_action = lttng_action_list_borrow_mutable_at_index(action, i);
+               for (auto inner_action : lttng::ctl::action_list_view(action)) {
                        LTTNG_ASSERT(inner_action);
+
                        ret = add_action_to_subitem_array(inner_action, subitems);
                        if (ret) {
                                goto end;
@@ -1049,7 +1043,7 @@ static int add_action_to_subitem_array(struct lttng_action *action,
         * now we leave the decision to skip to the action executor for sake of
         * simplicity and consistency.
         */
-       if (session_name != NULL) {
+       if (session_name != nullptr) {
                uint64_t session_id;
 
                /*
This page took 0.027232 seconds and 4 git commands to generate.