SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / src / bin / lttng-sessiond / action-executor.c
index 2e6e27a8ce3febcfd0db7cbb100369ff7d974ca4..8df560e0fb1b69d07753db639e15b8ab38413dac 100644 (file)
 #include <common/optional.h>
 #include <lttng/action/action-internal.h>
 #include <lttng/action/group.h>
 #include <common/optional.h>
 #include <lttng/action/action-internal.h>
 #include <lttng/action/group.h>
+#include <lttng/action/notify-internal.h>
 #include <lttng/action/notify.h>
 #include <lttng/action/rotate-session.h>
 #include <lttng/action/snapshot-session.h>
 #include <lttng/action/start-session.h>
 #include <lttng/action/stop-session.h>
 #include <lttng/condition/evaluation.h>
 #include <lttng/action/notify.h>
 #include <lttng/action/rotate-session.h>
 #include <lttng/action/snapshot-session.h>
 #include <lttng/action/start-session.h>
 #include <lttng/action/stop-session.h>
 #include <lttng/condition/evaluation.h>
+#include <lttng/condition/event-rule-internal.h>
 #include <lttng/lttng-error.h>
 #include <lttng/trigger/trigger-internal.h>
 #include <pthread.h>
 #include <lttng/lttng-error.h>
 #include <lttng/trigger/trigger-internal.h>
 #include <pthread.h>
@@ -104,7 +106,7 @@ static const char *action_type_names[] = {
 
 static const char *get_action_name(const struct lttng_action *action)
 {
 
 static const char *get_action_name(const struct lttng_action *action)
 {
-       return action_type_names[lttng_action_get_type_const(action)];
+       return action_type_names[lttng_action_get_type(action)];
 }
 
 /* Check if this trigger allowed to interect with a given session. */
 }
 
 /* Check if this trigger allowed to interect with a given session. */
@@ -113,27 +115,37 @@ static bool is_trigger_allowed_for_session(const struct lttng_trigger *trigger,
 {
        bool is_allowed = false;
        const struct lttng_credentials session_creds = {
 {
        bool is_allowed = false;
        const struct lttng_credentials session_creds = {
-               .uid = session->uid,
-               .gid = session->gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid),
        };
        /* Can never be NULL. */
        const struct lttng_credentials *trigger_creds =
                        lttng_trigger_get_credentials(trigger);
 
        };
        /* Can never be NULL. */
        const struct lttng_credentials *trigger_creds =
                        lttng_trigger_get_credentials(trigger);
 
-       is_allowed = (trigger_creds->uid == session_creds.uid) ||
-                       (trigger_creds->uid == 0);
+       is_allowed = (lttng_credentials_is_equal_uid(trigger_creds, &session_creds)) ||
+                       (lttng_credentials_get_uid(trigger_creds) == 0);
        if (!is_allowed) {
        if (!is_allowed) {
-               WARN("Trigger is not allowed to interact with session `%s`: session uid = %ld, session gid = %ld, trigger uid = %ld, trigger gid = %ld",
+               WARN("Trigger is not allowed to interact with session `%s`: session uid = %ld, session gid = %ld, trigger uid = %ld",
                                session->name,
                                (long int) session->uid,
                                (long int) session->gid,
                                session->name,
                                (long int) session->uid,
                                (long int) session->gid,
-                               (long int) trigger_creds->uid,
-                               (long int) trigger_creds->gid);
+                               (long int) lttng_credentials_get_uid(trigger_creds));
        }
 
        return is_allowed;
 }
 
        }
 
        return is_allowed;
 }
 
+static const char *get_trigger_name(const struct lttng_trigger *trigger)
+{
+       const char *trigger_name;
+       enum lttng_trigger_status trigger_status;
+
+       trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+       assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+       return trigger_name;
+}
+
 static int client_handle_transmission_status(
                struct notification_client *client,
                enum client_transmission_status status,
 static int client_handle_transmission_status(
                struct notification_client *client,
                enum client_transmission_status status,
@@ -184,9 +196,10 @@ static int action_executor_notify_handler(struct action_executor *executor,
                        lttng_trigger_get_const_condition(work_item->trigger),
                        work_item->evaluation,
                        lttng_trigger_get_credentials(work_item->trigger),
                        lttng_trigger_get_const_condition(work_item->trigger),
                        work_item->evaluation,
                        lttng_trigger_get_credentials(work_item->trigger),
-                       LTTNG_OPTIONAL_GET_PTR(work_item->object_creds),
-                       client_handle_transmission_status,
-                       executor);
+                       work_item->object_creds.is_set ?
+                                       &(work_item->object_creds.value) :
+                                       NULL,
+                       client_handle_transmission_status, executor);
 }
 
 static int action_executor_start_session_handler(struct action_executor *executor,
 }
 
 static int action_executor_start_session_handler(struct action_executor *executor,
@@ -211,9 +224,9 @@ static int action_executor_start_session_handler(struct action_executor *executo
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
-               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%p`",
+               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
                                session_name, get_action_name(action),
                                session_name, get_action_name(action),
-                   work_item->trigger);
+                               get_trigger_name(work_item->trigger));
                goto error_unlock_list;
        }
 
                goto error_unlock_list;
        }
 
@@ -225,16 +238,16 @@ static int action_executor_start_session_handler(struct action_executor *executo
        cmd_ret = cmd_start_trace(session);
        switch (cmd_ret) {
        case LTTNG_OK:
        cmd_ret = cmd_start_trace(session);
        switch (cmd_ret) {
        case LTTNG_OK:
-               DBG("Successfully started session `%s` on behalf of trigger `%p`",
-                               session_name, work_item->trigger);
+               DBG("Successfully started session `%s` on behalf of trigger `%s`",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        case LTTNG_ERR_TRACE_ALREADY_STARTED:
                break;
        case LTTNG_ERR_TRACE_ALREADY_STARTED:
-               DBG("Attempted to start session `%s` on behalf of trigger `%p` but it was already started",
-                               session_name, work_item->trigger);
+               DBG("Attempted to start session `%s` on behalf of trigger `%s` but it was already started",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        default:
                break;
        default:
-               WARN("Failed to start session `%s` on behalf of trigger `%p`: %s",
-                               session_name, work_item->trigger,
+               WARN("Failed to start session `%s` on behalf of trigger `%s`: %s",
+                               session_name, get_trigger_name(work_item->trigger),
                                lttng_strerror(-cmd_ret));
                break;
        }
                                lttng_strerror(-cmd_ret));
                break;
        }
@@ -270,9 +283,9 @@ static int action_executor_stop_session_handler(struct action_executor *executor
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
-               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%p`",
+               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
                                session_name, get_action_name(action),
                                session_name, get_action_name(action),
-                   work_item->trigger);
+                               get_trigger_name(work_item->trigger));
                goto error_unlock_list;
        }
 
                goto error_unlock_list;
        }
 
@@ -284,16 +297,16 @@ static int action_executor_stop_session_handler(struct action_executor *executor
        cmd_ret = cmd_stop_trace(session);
        switch (cmd_ret) {
        case LTTNG_OK:
        cmd_ret = cmd_stop_trace(session);
        switch (cmd_ret) {
        case LTTNG_OK:
-               DBG("Successfully stopped session `%s` on behalf of trigger `%p`",
-                               session_name, work_item->trigger);
+               DBG("Successfully stopped session `%s` on behalf of trigger `%s`",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        case LTTNG_ERR_TRACE_ALREADY_STOPPED:
                break;
        case LTTNG_ERR_TRACE_ALREADY_STOPPED:
-               DBG("Attempted to stop session `%s` on behalf of trigger `%p` but it was already stopped",
-                               session_name, work_item->trigger);
+               DBG("Attempted to stop session `%s` on behalf of trigger `%s` but it was already stopped",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        default:
                break;
        default:
-               WARN("Failed to stop session `%s` on behalf of trigger `%p`: %s",
-                               session_name, work_item->trigger,
+               WARN("Failed to stop session `%s` on behalf of trigger `%s`: %s",
+                               session_name, get_trigger_name(work_item->trigger),
                                lttng_strerror(-cmd_ret));
                break;
        }
                                lttng_strerror(-cmd_ret));
                break;
        }
@@ -329,9 +342,9 @@ static int action_executor_rotate_session_handler(struct action_executor *execut
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
        session_lock_list();
        session = session_find_by_name(session_name);
        if (!session) {
-               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%p`",
+               DBG("Failed to find session `%s` by name while executing `%s` action of trigger `%s`",
                                session_name, get_action_name(action),
                                session_name, get_action_name(action),
-                   work_item->trigger);
+                               get_trigger_name(work_item->trigger));
                goto error_unlock_list;
        }
 
                goto error_unlock_list;
        }
 
@@ -344,21 +357,21 @@ static int action_executor_rotate_session_handler(struct action_executor *execut
                        LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
        switch (cmd_ret) {
        case LTTNG_OK:
                        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 `%p`",
-                               session_name, work_item->trigger);
+               DBG("Successfully started rotation of session `%s` on behalf of trigger `%s`",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        case LTTNG_ERR_ROTATION_PENDING:
                break;
        case LTTNG_ERR_ROTATION_PENDING:
-               DBG("Attempted to start a rotation of session `%s` on behalf of trigger `%p` but a rotation is already ongoing",
-                               session_name, work_item->trigger);
+               DBG("Attempted to start a rotation of session `%s` on behalf of trigger `%s` but a rotation is already ongoing",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        case LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP:
        case LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR:
                break;
        case LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP:
        case LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR:
-               DBG("Attempted to start a rotation of session `%s` on behalf of trigger `%p` but a rotation has already been completed since the last stop or clear",
-                               session_name, work_item->trigger);
+               DBG("Attempted to start a rotation of session `%s` on behalf of trigger `%s` but a rotation has already been completed since the last stop or clear",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        default:
                break;
        default:
-               WARN("Failed to start a rotation of session `%s` on behalf of trigger `%p`: %s",
-                               session_name, work_item->trigger,
+               WARN("Failed to start a rotation of session `%s` on behalf of trigger `%s`: %s",
+                               session_name, get_trigger_name(work_item->trigger),
                                lttng_strerror(-cmd_ret));
                break;
        }
                                lttng_strerror(-cmd_ret));
                break;
        }
@@ -424,12 +437,12 @@ static int action_executor_snapshot_session_handler(struct action_executor *exec
        cmd_ret = cmd_snapshot_record(session, snapshot_output, 0);
        switch (cmd_ret) {
        case LTTNG_OK:
        cmd_ret = cmd_snapshot_record(session, snapshot_output, 0);
        switch (cmd_ret) {
        case LTTNG_OK:
-               DBG("Successfully recorded snapshot of session `%s` on behalf of trigger `%p`",
-                               session_name, work_item->trigger);
+               DBG("Successfully recorded snapshot of session `%s` on behalf of trigger `%s`",
+                               session_name, get_trigger_name(work_item->trigger));
                break;
        default:
                break;
        default:
-               WARN("Failed to record snapshot of session `%s` on behalf of trigger `%p`: %s",
-                               session_name, work_item->trigger,
+               WARN("Failed to record snapshot of session `%s` on behalf of trigger `%s`: %s",
+                               session_name, get_trigger_name(work_item->trigger),
                                lttng_strerror(-cmd_ret));
                break;
        }
                                lttng_strerror(-cmd_ret));
                break;
        }
@@ -468,8 +481,8 @@ static int action_executor_group_handler(struct action_executor *executor,
                ret = action_executor_generic_handler(
                                executor, work_item, action);
                if (ret) {
                ret = action_executor_generic_handler(
                                executor, work_item, action);
                if (ret) {
-                       ERR("Stopping the execution of the action group of trigger `%p` following a fatal error",
-                                       work_item->trigger);
+                       ERR("Stopping the execution of the action group of trigger `%s` following a fatal error",
+                                       get_trigger_name(work_item->trigger));
                        goto end;
                }
        }
                        goto end;
                }
        }
@@ -481,12 +494,12 @@ static int action_executor_generic_handler(struct action_executor *executor,
                const struct action_work_item *work_item,
                const struct lttng_action *action)
 {
                const struct action_work_item *work_item,
                const struct lttng_action *action)
 {
-       DBG("Executing action `%s` of trigger `%p` action work item %" PRIu64,
+       DBG("Executing action `%s` of trigger `%s` action work item %" PRIu64,
                        get_action_name(action),
                        get_action_name(action),
-                       work_item->trigger,
+                       get_trigger_name(work_item->trigger),
                        work_item->id);
 
                        work_item->id);
 
-       return action_executors[lttng_action_get_type_const(action)](
+       return action_executors[lttng_action_get_type(action)](
                        executor, work_item, action);
 }
 
                        executor, work_item, action);
 }
 
@@ -497,11 +510,11 @@ static int action_work_item_execute(struct action_executor *executor,
        const struct lttng_action *action =
                        lttng_trigger_get_const_action(work_item->trigger);
 
        const struct lttng_action *action =
                        lttng_trigger_get_const_action(work_item->trigger);
 
-       DBG("Starting execution of action work item %" PRIu64 " of trigger `%p`",
-                       work_item->id, work_item->trigger);
+       DBG("Starting execution of action work item %" PRIu64 " of trigger `%s`",
+                       work_item->id, get_trigger_name(work_item->trigger));
        ret = action_executor_generic_handler(executor, work_item, action);
        ret = action_executor_generic_handler(executor, work_item, action);
-       DBG("Completed execution of action work item %" PRIu64 " of trigger `%p`",
-                       work_item->id, work_item->trigger);
+       DBG("Completed execution of action work item %" PRIu64 " of trigger `%s`",
+                       work_item->id, get_trigger_name(work_item->trigger));
        return ret;
 }
 
        return ret;
 }
 
@@ -541,7 +554,7 @@ static void *action_executor_thread(void *_data)
                        continue;
                }
 
                        continue;
                }
 
-               /* Pop item from front of the listwith work lock held. */
+               /* Pop item from front of the list with work lock held. */
                work_item = cds_list_first_entry(&executor->work.list,
                                struct action_work_item, list_node);
                cds_list_del(&work_item->list_node);
                work_item = cds_list_first_entry(&executor->work.list,
                                struct action_work_item, list_node);
                cds_list_del(&work_item->list_node);
@@ -636,8 +649,8 @@ void action_executor_destroy(struct action_executor *executor)
        cds_list_for_each_entry_safe (
                        work_item, tmp, &executor->work.list, list_node) {
                WARN("Discarding action work item %" PRIu64
        cds_list_for_each_entry_safe (
                        work_item, tmp, &executor->work.list, list_node) {
                WARN("Discarding action work item %" PRIu64
-                               " associated to trigger `%p`",
-                               work_item->id, work_item->trigger);
+                               " associated to trigger `%s`",
+                               work_item->id, get_trigger_name(work_item->trigger));
                cds_list_del(&work_item->list_node);
                action_work_item_destroy(work_item);
        }
                cds_list_del(&work_item->list_node);
                action_work_item_destroy(work_item);
        }
@@ -662,9 +675,9 @@ enum action_executor_status action_executor_enqueue(
        /* Check for queue overflow. */
        if (executor->work.pending_count >= MAX_QUEUED_WORK_COUNT) {
                /* Most likely spammy, remove if it is the case. */
        /* Check for queue overflow. */
        if (executor->work.pending_count >= MAX_QUEUED_WORK_COUNT) {
                /* Most likely spammy, remove if it is the case. */
-               DBG("Refusing to enqueue action for trigger `%p` as work item %" PRIu64
-                   " (overflow)",
-                               trigger, work_item_id);
+               DBG("Refusing to enqueue action for trigger `%s` as work item %" PRIu64
+                       " (overflow)",
+                               get_trigger_name(trigger), work_item_id);
                executor_status = ACTION_EXECUTOR_STATUS_OVERFLOW;
                goto error_unlock;
        }
                executor_status = ACTION_EXECUTOR_STATUS_OVERFLOW;
                goto error_unlock;
        }
@@ -672,7 +685,7 @@ enum action_executor_status action_executor_enqueue(
        work_item = zmalloc(sizeof(*work_item));
        if (!work_item) {
                PERROR("Failed to allocate action executor work item on behalf of trigger `%p`",
        work_item = zmalloc(sizeof(*work_item));
        if (!work_item) {
                PERROR("Failed to allocate action executor work item on behalf of trigger `%p`",
-                               trigger);
+                               get_trigger_name(trigger));
                executor_status = ACTION_EXECUTOR_STATUS_ERROR;
                goto error_unlock;
        }
                executor_status = ACTION_EXECUTOR_STATUS_ERROR;
                goto error_unlock;
        }
@@ -703,7 +716,7 @@ enum action_executor_status action_executor_enqueue(
        cds_list_add_tail(&work_item->list_node, &executor->work.list);
        executor->work.pending_count++;
        DBG("Enqueued action for trigger `%p` as work item %" PRIu64,
        cds_list_add_tail(&work_item->list_node, &executor->work.list);
        executor->work.pending_count++;
        DBG("Enqueued action for trigger `%p` as work item %" PRIu64,
-                       trigger, work_item_id);
+                       get_trigger_name(trigger), work_item_id);
        signal = true;
 
 error_unlock:
        signal = true;
 
 error_unlock:
This page took 0.046824 seconds and 5 git commands to generate.