X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Faction-executor.c;h=f982b7065e5b357c88b344e3e8805842f1779310;hp=c51bb7f639cd7143d3301fbac8c2b385715ece11;hb=64eafdf60552bbd7e22fb1c8fc8fc2b42a3cf68b;hpb=f2b3ef9f7d7adf6cc0678cd5933b638f5a9e75a6 diff --git a/src/bin/lttng-sessiond/action-executor.c b/src/bin/lttng-sessiond/action-executor.c index c51bb7f63..f982b7065 100644 --- a/src/bin/lttng-sessiond/action-executor.c +++ b/src/bin/lttng-sessiond/action-executor.c @@ -104,7 +104,11 @@ static const char *action_type_names[] = { static const char *get_action_name(const struct lttng_action *action) { - return action_type_names[lttng_action_get_type_const(action)]; + const enum lttng_action_type action_type = lttng_action_get_type(action); + + assert(action_type != LTTNG_ACTION_TYPE_UNKNOWN); + + return action_type_names[action_type]; } /* Check if this trigger allowed to interect with a given session. */ @@ -113,22 +117,21 @@ static bool is_trigger_allowed_for_session(const struct lttng_trigger *trigger, { 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); - 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) { - 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, - (long int) trigger_creds->uid, - (long int) trigger_creds->gid); + (long int) lttng_credentials_get_uid(trigger_creds)); } return is_allowed; @@ -143,8 +146,6 @@ static int client_handle_transmission_status( struct action_executor *executor = user_data; bool update_communication = true; - ASSERT_LOCKED(client->lock); - switch (status) { case CLIENT_TRANSMISSION_STATUS_COMPLETE: DBG("Successfully sent full notification to client, client_id = %" PRIu64, @@ -158,12 +159,10 @@ static int client_handle_transmission_status( case CLIENT_TRANSMISSION_STATUS_FAIL: DBG("Communication error occurred while sending notification to client, client_id = %" PRIu64, client->id); - client->communication.active = false; break; default: ERR("Fatal error encoutered while sending notification to client, client_id = %" PRIu64, client->id); - client->communication.active = false; ret = -1; goto end; } @@ -172,6 +171,7 @@ static int client_handle_transmission_status( goto end; } + /* Safe to read client's id without locking as it is immutable. */ ret = notification_thread_client_communication_update( executor->notification_thread_handle, client->id, status); @@ -188,8 +188,7 @@ static int action_executor_notify_handler(struct action_executor *executor, work_item->evaluation, lttng_trigger_get_credentials(work_item->trigger), LTTNG_OPTIONAL_GET_PTR(work_item->object_creds), - client_handle_transmission_status, - executor); + client_handle_transmission_status, executor); } static int action_executor_start_session_handler(struct action_executor *executor, @@ -484,12 +483,16 @@ static int action_executor_generic_handler(struct action_executor *executor, const struct action_work_item *work_item, const struct lttng_action *action) { + const enum lttng_action_type action_type = lttng_action_get_type(action); + + assert(action_type != LTTNG_ACTION_TYPE_UNKNOWN); + DBG("Executing action `%s` of trigger `%p` action work item %" PRIu64, get_action_name(action), work_item->trigger, work_item->id); - return action_executors[lttng_action_get_type_const(action)]( + return action_executors[action_type]( executor, work_item, action); } @@ -544,7 +547,7 @@ static void *action_executor_thread(void *_data) 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); @@ -566,7 +569,9 @@ static void *action_executor_thread(void *_data) pthread_mutex_lock(&executor->work.lock); } - pthread_mutex_unlock(&executor->work.lock); + if (executor->should_quit) { + pthread_mutex_unlock(&executor->work.lock); + } DBG("Left work execution loop"); health_code_update(); @@ -664,8 +669,7 @@ enum action_executor_status action_executor_enqueue( 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); + " (overflow)", trigger, work_item_id); executor_status = ACTION_EXECUTOR_STATUS_OVERFLOW; goto error_unlock; }