Fix: ust: segfault on lttng start on filter bytecode copy
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
index c7768a547bf83e2d9e33450de1fe2362b2a5a0ec..4861a32856bfdce04dbde1c998819867a303ef55 100644 (file)
@@ -13,7 +13,7 @@
 #include <common/compat/errno.h>
 #include <lttng/lttng.h>
 #include <lttng/condition/condition.h>
-#include <lttng/condition/event-rule.h>
+#include <lttng/condition/event-rule-matches.h>
 #include <lttng/event-rule/event-rule.h>
 #include <lttng/event-rule/event-rule-internal.h>
 #include <common/bytecode/bytecode.h>
@@ -48,7 +48,7 @@ static void add_unique_ust_event(struct lttng_ht *ht,
        assert(event);
 
        key.name = event->attr.name;
-       key.filter = (struct lttng_filter_bytecode *) event->filter;
+       key.filter = (struct lttng_bytecode *) event->filter;
        key.loglevel_type = event->attr.loglevel_type;
        key.loglevel_value = event->attr.loglevel;
        key.exclusion = event->exclusion;
@@ -105,7 +105,7 @@ int event_kernel_disable_event(struct ltt_kernel_channel *kchan,
  */
 int event_kernel_enable_event(struct ltt_kernel_channel *kchan,
                struct lttng_event *event, char *filter_expression,
-               struct lttng_filter_bytecode *filter)
+               struct lttng_bytecode *filter)
 {
        int ret;
        struct ltt_kernel_event *kevent;
@@ -155,7 +155,7 @@ end:
 int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct lttng_event *event,
                char *filter_expression,
-               struct lttng_filter_bytecode *filter,
+               struct lttng_bytecode *filter,
                struct lttng_event_exclusion *exclusion,
                bool internal_event)
 {
@@ -169,7 +169,7 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
        rcu_read_lock();
 
        uevent = trace_ust_find_event(uchan->events, event->name, filter,
-                       (enum lttng_ust_loglevel_type) event->loglevel_type,
+                       (enum lttng_ust_abi_loglevel_type) event->loglevel_type,
                        event->loglevel, exclusion);
        if (!uevent) {
                ret = trace_ust_create_event(event, filter_expression,
@@ -179,7 +179,7 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
                filter = NULL;
                exclusion = NULL;
                if (ret != LTTNG_OK) {
-                       goto error;
+                       goto end;
                }
 
                /* Valid to set it after the goto error since uevent is still NULL */
@@ -214,11 +214,10 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
        if (ret < 0) {
                if (ret == -LTTNG_UST_ERR_EXIST) {
                        ret = LTTNG_ERR_UST_EVENT_EXIST;
-                       goto end;
                } else {
                        ret = LTTNG_ERR_UST_ENABLE_FAIL;
-                       goto error;
                }
+               goto end;
        }
 
        DBG("Event UST %s %s in channel %s", uevent->attr.name,
@@ -232,24 +231,6 @@ end:
        free(filter);
        free(exclusion);
        return ret;
-
-error:
-       /*
-        * Only destroy event on creation time (not enabling time) because if the
-        * event is found in the channel (to_create == 0), it means that at some
-        * point the enable_event worked and it's thus valid to keep it alive.
-        * Destroying it also implies that we also destroy it's shadow copy to sync
-        * everyone up.
-        */
-       if (to_create) {
-               /* In this code path, the uevent was not added to the hash table */
-               trace_ust_destroy_event(uevent);
-       }
-       rcu_read_unlock();
-       free(filter_expression);
-       free(filter);
-       free(exclusion);
-       return ret;
 }
 
 /*
@@ -393,7 +374,7 @@ static void agent_enable_all(struct agent *agt)
  */
 int event_agent_enable_all(struct ltt_ust_session *usess,
                struct agent *agt, struct lttng_event *event,
-               struct lttng_filter_bytecode *filter ,char *filter_expression)
+               struct lttng_bytecode *filter ,char *filter_expression)
 {
        int ret;
 
@@ -422,7 +403,7 @@ error:
  * contexts yet. Not an issue for now, since they are not generated by
  * the lttng-ctl library.
  */
-static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode,
+static int add_filter_app_ctx(struct lttng_bytecode *bytecode,
                const char *filter_expression, struct agent *agt)
 {
        int ret = LTTNG_OK;
@@ -481,7 +462,7 @@ end:
 
 static int agent_enable(struct agent *agt,
                struct lttng_event *event,
-               struct lttng_filter_bytecode *filter,
+               struct lttng_bytecode *filter,
                char *filter_expression)
 {
        int ret, created = 0;
@@ -551,7 +532,7 @@ end:
 int event_agent_enable(struct ltt_ust_session *usess,
                struct agent *agt,
                struct lttng_event *event,
-               struct lttng_filter_bytecode *filter,
+               struct lttng_bytecode *filter,
                char *filter_expression)
 {
        assert(usess);
@@ -581,8 +562,8 @@ int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
        const struct lttng_event_rule *rule;
        const char *filter_expression;
        char *filter_expression_copy = NULL;
-       const struct lttng_filter_bytecode *filter_bytecode;
-       struct lttng_filter_bytecode *filter_bytecode_copy = NULL;
+       const struct lttng_bytecode *filter_bytecode;
+       struct lttng_bytecode *filter_bytecode_copy = NULL;
        struct lttng_event *event = NULL;
        uid_t trigger_owner_uid = 0;
        const char *trigger_name;
@@ -592,7 +573,7 @@ int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
 
        t_status = lttng_trigger_get_name(trigger, &trigger_name);
        if (t_status != LTTNG_TRIGGER_STATUS_OK) {
-               trigger_name = "(unnamed)";
+               trigger_name = "(anonymous)";
        }
 
        t_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner_uid);
@@ -601,13 +582,21 @@ int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
        condition = lttng_trigger_get_const_condition(trigger);
 
        assert(lttng_condition_get_type(condition) ==
-                       LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
+                       LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
 
-       c_status = lttng_condition_event_rule_get_rule(condition, &rule);
+       c_status = lttng_condition_event_rule_matches_get_rule(
+                       condition, &rule);
        assert(c_status == LTTNG_CONDITION_STATUS_OK);
 
-       assert(lttng_event_rule_get_type(rule) ==
-                       LTTNG_EVENT_RULE_TYPE_TRACEPOINT);
+       switch (lttng_event_rule_get_type(rule)) {
+       case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING:
+       case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING:
+       case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING:
+               break;
+       default:
+               abort();
+               break;
+       }
 
        d_type = lttng_event_rule_get_domain_type(rule);
        assert(d_type == agt->domain);
@@ -631,7 +620,7 @@ int trigger_agent_enable(const struct lttng_trigger *trigger, struct agent *agt)
                filter_bytecode = lttng_event_rule_get_filter_bytecode(rule);
                if (filter_bytecode) {
                        filter_bytecode_copy =
-                                       lttng_filter_bytecode_copy(filter_bytecode);
+                                       lttng_bytecode_copy(filter_bytecode);
                        if (!filter_bytecode_copy) {
                                ret = LTTNG_ERR_NOMEM;
                                goto end;
@@ -780,7 +769,7 @@ static int event_agent_disable_one(struct ltt_ust_session *usess,
         * ignored since the type is LTTNG_UST_LOGLEVEL_ALL.
         */
        uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
-                       aevent->filter, LTTNG_UST_LOGLEVEL_ALL, -1, NULL);
+                       aevent->filter, LTTNG_UST_ABI_LOGLEVEL_ALL, -1, NULL);
        /* If the agent event exists, it must be available on the UST side. */
        assert(uevent);
 
This page took 0.02765 seconds and 4 git commands to generate.