+ struct lttng_trigger_ht_element *trigger_ht_element)
+{
+ assert(state);
+ assert(trigger_ht_element);
+
+ cds_lfht_del(state->triggers_ht, &trigger_ht_element->node);
+ cds_lfht_del(state->triggers_by_name_uid_ht, &trigger_ht_element->node_by_name_uid);
+}
+
+static
+enum lttng_error_code setup_tracer_notifier(
+ struct notification_thread_state *state,
+ struct lttng_trigger *trigger)
+{
+ enum lttng_error_code ret;
+ enum event_notifier_error_accounting_status error_accounting_status;
+ struct cds_lfht_node *node;
+ uint64_t error_counter_index = 0;
+ struct lttng_condition *condition = lttng_trigger_get_condition(trigger);
+ struct notification_trigger_tokens_ht_element *trigger_tokens_ht_element = NULL;
+
+ trigger_tokens_ht_element = zmalloc(sizeof(*trigger_tokens_ht_element));
+ if (!trigger_tokens_ht_element) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ /* Add trigger token to the trigger_tokens_ht. */
+ cds_lfht_node_init(&trigger_tokens_ht_element->node);
+ trigger_tokens_ht_element->token = LTTNG_OPTIONAL_GET(trigger->tracer_token);
+ trigger_tokens_ht_element->trigger = trigger;
+
+ node = cds_lfht_add_unique(state->trigger_tokens_ht,
+ hash_key_u64(&trigger_tokens_ht_element->token, lttng_ht_seed),
+ match_trigger_token,
+ &trigger_tokens_ht_element->token,
+ &trigger_tokens_ht_element->node);
+ if (node != &trigger_tokens_ht_element->node) {
+ ret = LTTNG_ERR_TRIGGER_EXISTS;
+ goto error_free_ht_element;
+ }
+
+ error_accounting_status = event_notifier_error_accounting_register_event_notifier(
+ trigger, &error_counter_index);
+ if (error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
+ if (error_accounting_status == EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NO_INDEX_AVAILABLE) {
+ DBG("Trigger list error accounting counter full.");
+ ret = LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING_FULL;
+ } else {
+ ERR("Error registering trigger for error accounting");
+ ret = LTTNG_ERR_EVENT_NOTIFIER_REGISTRATION;
+ }
+
+ goto error_remove_ht_element;
+ }
+
+ lttng_condition_event_rule_matches_set_error_counter_index(
+ condition, error_counter_index);
+
+ ret = LTTNG_OK;
+ goto end;
+
+error_remove_ht_element:
+ cds_lfht_del(state->trigger_tokens_ht, &trigger_tokens_ht_element->node);
+error_free_ht_element:
+ free(trigger_tokens_ht_element);
+end:
+ return ret;
+}
+
+/*
+ * FIXME A client's credentials are not checked when registering a trigger.
+ *
+ * The effects of this are benign since:
+ * - The client will succeed in registering the trigger, as it is valid,
+ * - The trigger will, internally, be bound to the channel/session,
+ * - The notifications will not be sent since the client's credentials
+ * are checked against the channel at that moment.
+ *
+ * If this function returns a non-zero value, it means something is
+ * fundamentally broken and the whole subsystem/thread will be torn down.
+ *
+ * If a non-fatal error occurs, just set the cmd_result to the appropriate
+ * error code.
+ */
+static
+int handle_notification_thread_command_register_trigger(
+ struct notification_thread_state *state,
+ struct lttng_trigger *trigger,
+ bool is_trigger_anonymous,
+ enum lttng_error_code *cmd_result)