+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Synchronize tracers, only if needed */
+ /* TODO: maybe extract somewhere else */
+ {
+ struct lttng_condition *condition = NULL;
+ condition = lttng_trigger_get_condition(trigger);
+ if (!condition) {
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ if (lttng_condition_get_type(condition) == LTTNG_CONDITION_TYPE_EVENT_RULE_HIT) {
+ const struct lttng_event_rule *rule = NULL;
+ (void) lttng_condition_event_rule_get_rule(condition, &rule);
+ if (!rule) {
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+ if (lttng_event_rule_get_domain_type(rule) == LTTNG_DOMAIN_KERNEL) {
+ /* TODO: get the token value from the
+ * notification thread and only perform an
+ * enable and a disable.... This is NOT
+ * OPTIMIZED AT ALL
+ */
+ ret = kernel_register_trigger(trigger, &cmd_creds);
+ if (ret != LTTNG_OK) {
+ enum lttng_error_code notif_thread_unregister_ret =
+ notification_thread_command_unregister_trigger(
+ notification_thread,
+ trigger);
+ if (notif_thread_unregister_ret != LTTNG_OK) {
+ ERR("Error unregistering notification thread trigger after kernel registration failure.");
+ }
+ goto end;
+
+ }
+ } else {
+ /* TODO: get the token value from the
+ * notification thread and only perform an
+ * enable and a disable.... This is NOT
+ * OPTIMIZED AT ALL
+ */
+ ust_app_global_update_all_tokens();
+ /* Agent handling */
+ if (lttng_event_rule_is_agent(rule)) {
+ struct agent *agt;
+ const char *pattern;
+ enum lttng_domain_type domain_type;
+ domain_type = lttng_event_rule_get_domain_type(
+ rule);
+ (void) lttng_event_rule_tracepoint_get_pattern(
+ rule, &pattern);
+ agt = trigger_find_agent(domain_type);
+ if (!agt) {
+ agt = agent_create(domain_type);
+ if (!agt) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ agent_add(agt, trigger_agents_ht_by_domain);
+ }
+
+ ret = trigger_agent_enable(
+ trigger, agt);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+ }
+ }
+ }
+ }
+
+ /* Return an image of the updated object to the client */
+ *return_trigger = trigger;
+ /* Ownership of trigger was transferred to caller. */