Rename on-event to event-rule-matches
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index d8546308deb2cc2fa77e7c1b698627626b881234..97cb6623250c9384dfdabbd227772870261687fe 100644 (file)
@@ -29,8 +29,8 @@
 #include <lttng/event-rule/event-rule-internal.h>
 #include <lttng/event-rule/tracepoint.h>
 #include <lttng/condition/condition.h>
-#include <lttng/condition/on-event-internal.h>
-#include <lttng/condition/on-event.h>
+#include <lttng/condition/event-rule-matches-internal.h>
+#include <lttng/condition/event-rule-matches.h>
 #include <lttng/trigger/trigger-internal.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 
@@ -1011,7 +1011,7 @@ void delete_ust_app(struct ust_app *app)
                                app->event_notifier_group.event_pipe);
 
                ret_code = notification_thread_command_remove_tracer_event_source(
-                               notification_thread_handle,
+                               the_notification_thread_handle,
                                event_notifier_read_fd);
                if (ret_code != LTTNG_OK) {
                        ERR("Failed to remove application tracer event source from notification thread");
@@ -1266,11 +1266,16 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule(
 
        condition = lttng_trigger_get_condition(trigger);
        assert(condition);
-       assert(lttng_condition_get_type(condition) == LTTNG_CONDITION_TYPE_ON_EVENT);
+       assert(lttng_condition_get_type(condition) ==
+                       LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
 
-       assert(LTTNG_CONDITION_STATUS_OK == lttng_condition_on_event_get_rule(condition, &event_rule));
+       assert(LTTNG_CONDITION_STATUS_OK ==
+                       lttng_condition_event_rule_matches_get_rule(
+                                       condition, &event_rule));
        assert(event_rule);
 
+       ua_event_notifier_rule->error_counter_index =
+                       lttng_condition_event_rule_matches_get_error_counter_index(condition);
        /* Acquire the event notifier's reference to the trigger. */
        lttng_trigger_get(trigger);
 
@@ -2108,9 +2113,10 @@ static int create_ust_event_notifier(struct ust_app *app,
        condition = lttng_trigger_get_const_condition(
                        ua_event_notifier_rule->trigger);
        assert(condition);
-       assert(lttng_condition_get_type(condition) == LTTNG_CONDITION_TYPE_ON_EVENT);
+       assert(lttng_condition_get_type(condition) ==
+                       LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
 
-       condition_status = lttng_condition_on_event_get_rule(
+       condition_status = lttng_condition_event_rule_matches_get_rule(
                        condition, &event_rule);
        assert(condition_status == LTTNG_CONDITION_STATUS_OK);
 
@@ -2174,13 +2180,13 @@ static int create_ust_event_notifier(struct ust_app *app,
        }
 
        /* Set the capture bytecodes. */
-       cond_status = lttng_condition_on_event_get_capture_descriptor_count(
+       cond_status = lttng_condition_event_rule_matches_get_capture_descriptor_count(
                        condition, &capture_bytecode_count);
        assert(cond_status == LTTNG_CONDITION_STATUS_OK);
 
        for (i = 0; i < capture_bytecode_count; i++) {
                const struct lttng_bytecode *capture_bytecode =
-                               lttng_condition_on_event_get_capture_bytecode_at_index(
+                               lttng_condition_event_rule_matches_get_capture_bytecode_at_index(
                                                condition, i);
 
                ret = set_ust_capture(app, capture_bytecode, i,
@@ -2954,7 +2960,7 @@ static int do_consumer_create_channel(struct ltt_ust_session *usess,
        health_code_update();
 
        /*
-        * Now get the channel from the consumer. This call wil populate the stream
+        * Now get the channel from the consumer. This call will populate the stream
         * list of that channel and set the ust objects.
         */
        if (usess->consumer->enabled) {
@@ -3352,11 +3358,12 @@ static int create_channel_per_uid(struct ust_app *app,
        pthread_mutex_unlock(&reg_uid->registry->reg.ust->lock);
 
        notification_ret = notification_thread_command_add_channel(
-                       notification_thread_handle, session->name,
-                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
-                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
-                       ua_chan->name,
-                       ua_chan->key, LTTNG_DOMAIN_UST,
+                       the_notification_thread_handle, session->name,
+                       lttng_credentials_get_uid(
+                                       &ua_sess->effective_credentials),
+                       lttng_credentials_get_gid(
+                                       &ua_sess->effective_credentials),
+                       ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST,
                        ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf);
        if (notification_ret != LTTNG_OK) {
                ret = - (int) notification_ret;
@@ -3453,11 +3460,12 @@ static int create_channel_per_pid(struct ust_app *app,
        pthread_mutex_unlock(&registry->lock);
 
        cmd_ret = notification_thread_command_add_channel(
-                       notification_thread_handle, session->name,
-                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
-                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
-                       ua_chan->name,
-                       ua_chan->key, LTTNG_DOMAIN_UST,
+                       the_notification_thread_handle, session->name,
+                       lttng_credentials_get_uid(
+                                       &ua_sess->effective_credentials),
+                       lttng_credentials_get_gid(
+                                       &ua_sess->effective_credentials),
+                       ua_chan->name, ua_chan->key, LTTNG_DOMAIN_UST,
                        ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf);
        if (cmd_ret != LTTNG_OK) {
                ret = - (int) cmd_ret;
@@ -3850,9 +3858,11 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
        DBG3("UST app creating application for socket %d", sock);
 
        if ((msg->bits_per_long == 64 &&
-                               (uatomic_read(&ust_consumerd64_fd) == -EINVAL))
-                       || (msg->bits_per_long == 32 &&
-                               (uatomic_read(&ust_consumerd32_fd) == -EINVAL))) {
+                           (uatomic_read(&the_ust_consumerd64_fd) ==
+                                           -EINVAL)) ||
+                       (msg->bits_per_long == 32 &&
+                                       (uatomic_read(&the_ust_consumerd32_fd) ==
+                                                       -EINVAL))) {
                ERR("Registration failed: application \"%s\" (pid: %d) has "
                                "%d-bit long, but no consumerd for this size is available.\n",
                                msg->name, msg->pid, msg->bits_per_long);
@@ -4046,8 +4056,9 @@ int ust_app_setup_event_notifier_group(struct ust_app *app)
        lttng_fd_put(LTTNG_FD_APPS, 1);
 
        lttng_ret = notification_thread_command_add_tracer_event_source(
-                       notification_thread_handle,
-                       lttng_pipe_get_readfd(app->event_notifier_group.event_pipe),
+                       the_notification_thread_handle,
+                       lttng_pipe_get_readfd(
+                                       app->event_notifier_group.event_pipe),
                        LTTNG_DOMAIN_UST);
        if (lttng_ret != LTTNG_OK) {
                ERR("Failed to add tracer event source to notification thread");
@@ -4060,16 +4071,33 @@ int ust_app_setup_event_notifier_group(struct ust_app *app)
 
        event_notifier_error_accounting_status = event_notifier_error_accounting_register_app(app);
        if (event_notifier_error_accounting_status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
+               if (event_notifier_error_accounting_status == EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD) {
+                       DBG3("Failed to setup event notifier error accounting (application is dead): app socket fd = %d",
+                                       app->sock);
+                       ret = 0;
+                       goto error_accounting;
+               }
+
                ERR("Failed to setup event notifier error accounting for app");
                ret = -1;
-               goto error;
+               goto error_accounting;
        }
 
        return ret;
 
+error_accounting:
+       lttng_ret = notification_thread_command_remove_tracer_event_source(
+                       the_notification_thread_handle,
+                       lttng_pipe_get_readfd(
+                                       app->event_notifier_group.event_pipe));
+       if (lttng_ret != LTTNG_OK) {
+               ERR("Failed to remove application tracer event source from notification thread");
+       }
+
 error:
        ustctl_release_object(app->sock, app->event_notifier_group.object);
        free(app->event_notifier_group.object);
+       app->event_notifier_group.object = NULL;
        return ret;
 }
 
@@ -5645,7 +5673,7 @@ void ust_app_synchronize_event_notifier_rules(struct ust_app *app)
 
        /* Get all triggers using uid 0 (root) */
        ret_code = notification_thread_command_list_triggers(
-                       notification_thread_handle, 0, &triggers);
+                       the_notification_thread_handle, 0, &triggers);
        if (ret_code != LTTNG_OK) {
                ret = -1;
                goto end;
@@ -5673,12 +5701,15 @@ void ust_app_synchronize_event_notifier_rules(struct ust_app *app)
                token = lttng_trigger_get_tracer_token(trigger);
                condition = lttng_trigger_get_condition(trigger);
 
-               if (lttng_condition_get_type(condition) != LTTNG_CONDITION_TYPE_ON_EVENT) {
+               if (lttng_condition_get_type(condition) !=
+                               LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES) {
                        /* Does not apply */
                        continue;
                }
 
-               condition_status = lttng_condition_on_event_borrow_rule_mutable(condition, &event_rule);
+               condition_status =
+                               lttng_condition_event_rule_matches_borrow_rule_mutable(
+                                               condition, &event_rule);
                assert(condition_status == LTTNG_CONDITION_STATUS_OK);
 
                if (lttng_event_rule_get_domain_type(event_rule) == LTTNG_DOMAIN_KERNEL) {
@@ -5985,20 +6016,6 @@ void ust_app_global_update_all_event_notifier_rules(void)
        rcu_read_unlock();
 }
 
-void ust_app_update_event_notifier_error_count(struct lttng_trigger *trigger)
-{
-       uint64_t error_count = 0;
-       enum event_notifier_error_accounting_status status;
-       struct lttng_condition *condition = lttng_trigger_get_condition(trigger);
-
-       status = event_notifier_error_accounting_get_count(trigger, &error_count);
-       if (status != EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK) {
-               ERR("Error getting trigger error count.");
-       }
-
-       lttng_condition_on_event_set_error_count(condition, error_count);
-}
-
 /*
  * Add context to a specific channel for global UST domain.
  */
@@ -7112,11 +7129,6 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session)
                        struct buffer_reg_channel *buf_reg_chan;
                        struct consumer_socket *socket;
 
-                       if (!reg->registry->reg.ust->metadata_key) {
-                               /* Skip since no metadata is present */
-                               continue;
-                       }
-
                        /* Get consumer socket to use to push the metadata.*/
                        socket = consumer_find_socket_by_bitness(reg->bits_per_long,
                                        usess->consumer);
@@ -7139,6 +7151,19 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session)
                                }
                        }
 
+                       /*
+                        * The metadata channel might not be present.
+                        *
+                        * Consumer stream allocation can be done
+                        * asynchronously and can fail on intermediary
+                        * operations (i.e add context) and lead to data
+                        * channels created with no metadata channel.
+                        */
+                       if (!reg->registry->reg.ust->metadata_key) {
+                               /* Skip since no metadata is present. */
+                               continue;
+                       }
+
                        (void) push_metadata(reg->registry->reg.ust, usess->consumer);
 
                        ret = consumer_rotate_channel(socket,
This page took 0.029044 seconds and 5 git commands to generate.