Fix: sessiond: fix memory leak in receive_lttng_trigger
[lttng-tools.git] / src / bin / lttng-sessiond / agent.c
index 84728b7829cd5adbebed1ae0788dd74eb81f3b9a..10c2d7c85fd3085b186160663d59911935a7285c 100644 (file)
@@ -15,8 +15,9 @@
 #include <lttng/event-rule/event-rule-internal.h>
 #include <lttng/event-rule/tracepoint.h>
 #include <lttng/condition/condition.h>
-#include <lttng/condition/event-rule.h>
+#include <lttng/condition/on-event.h>
 #include <lttng/domain-internal.h>
+#include <lttng/log-level-rule-internal.h>
 
 #include <common/common.h>
 #include <common/sessiond-comm/agent.h>
@@ -676,7 +677,7 @@ int agent_enable_event(struct agent_event *event,
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+       cds_lfht_for_each_entry(the_agent_apps_ht_by_sock->ht, &iter.iter, app,
                        node.node) {
                if (app->domain != domain) {
                        continue;
@@ -751,7 +752,7 @@ int agent_enable_context(const struct lttng_event_context *ctx,
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+       cds_lfht_for_each_entry(the_agent_apps_ht_by_sock->ht, &iter.iter, app,
                        node.node) {
                struct agent_app_ctx *agent_ctx;
 
@@ -811,7 +812,7 @@ int agent_disable_event(struct agent_event *event,
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+       cds_lfht_for_each_entry(the_agent_apps_ht_by_sock->ht, &iter.iter, app,
                        node.node) {
                if (app->domain != domain) {
                        continue;
@@ -851,7 +852,7 @@ static int disable_context(struct agent_app_ctx *ctx,
        rcu_read_lock();
        DBG2("Disabling agent application context %s:%s",
                        ctx->provider_name, ctx->ctx_name);
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+       cds_lfht_for_each_entry(the_agent_apps_ht_by_sock->ht, &iter.iter, app,
                        node.node) {
                if (app->domain != domain) {
                        continue;
@@ -895,7 +896,7 @@ int agent_list_events(struct lttng_event **events,
        }
 
        rcu_read_lock();
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+       cds_lfht_for_each_entry(the_agent_apps_ht_by_sock->ht, &iter.iter, app,
                        node.node) {
                ssize_t nb_ev;
                struct lttng_event *agent_events;
@@ -993,7 +994,8 @@ struct agent_app *agent_find_app_by_sock(int sock)
 
        assert(sock >= 0);
 
-       lttng_ht_lookup(agent_apps_ht_by_sock, (void *)((unsigned long) sock), &iter);
+       lttng_ht_lookup(the_agent_apps_ht_by_sock,
+                       (void *) ((unsigned long) sock), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node == NULL) {
                goto error;
@@ -1016,7 +1018,7 @@ void agent_add_app(struct agent_app *app)
        assert(app);
 
        DBG3("Agent adding app sock: %d and pid: %d to ht", app->sock->fd, app->pid);
-       lttng_ht_add_unique_ulong(agent_apps_ht_by_sock, &app->node);
+       lttng_ht_add_unique_ulong(the_agent_apps_ht_by_sock, &app->node);
 }
 
 /*
@@ -1034,7 +1036,7 @@ void agent_delete_app(struct agent_app *app)
        DBG3("Agent deleting app pid: %d and sock: %d", app->pid, app->sock->fd);
 
        iter.iter.node = &app->node.node;
-       ret = lttng_ht_del(agent_apps_ht_by_sock, &iter);
+       ret = lttng_ht_del(the_agent_apps_ht_by_sock, &iter);
        assert(!ret);
 }
 
@@ -1128,7 +1130,7 @@ error:
  */
 struct agent_event *agent_create_event(const char *name,
                enum lttng_loglevel_type loglevel_type, int loglevel_value,
-               struct lttng_filter_bytecode *filter, char *filter_expression)
+               struct lttng_bytecode *filter, char *filter_expression)
 {
        struct agent_event *event = NULL;
 
@@ -1243,6 +1245,7 @@ struct agent_event *agent_find_event_by_trigger(
        const struct lttng_event_rule *rule;
        const char *name;
        const char *filter_expression;
+       const struct lttng_log_level_rule *log_level_rule;
        /* Unused when loglevel_type is 'ALL'. */
        int loglevel_value = 0;
        enum lttng_loglevel_type loglevel_type;
@@ -1253,9 +1256,9 @@ struct agent_event *agent_find_event_by_trigger(
        condition = lttng_trigger_get_const_condition(trigger);
 
        assert(lttng_condition_get_type(condition) ==
-                       LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
+                       LTTNG_CONDITION_TYPE_ON_EVENT);
 
-       c_status = lttng_condition_event_rule_get_rule(condition, &rule);
+       c_status = lttng_condition_on_event_get_rule(condition, &rule);
        assert(c_status == LTTNG_CONDITION_STATUS_OK);
 
        assert(lttng_event_rule_get_type(rule) ==
@@ -1272,14 +1275,16 @@ struct agent_event *agent_find_event_by_trigger(
        /* Get the internal filter expression. */
        filter_expression = lttng_event_rule_get_filter(rule);
 
-       er_status = lttng_event_rule_tracepoint_get_log_level_type(
-                       rule, &loglevel_type);
-       assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
-
-       if (loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
-               er_status = lttng_event_rule_tracepoint_get_log_level(
-                               rule, &loglevel_value);
-               assert(er_status == LTTNG_EVENT_RULE_STATUS_OK);
+       /* Map log_level_rule to loglevel value. */
+       er_status = lttng_event_rule_tracepoint_get_log_level_rule(
+                       rule, &log_level_rule);
+       if (er_status == LTTNG_EVENT_RULE_STATUS_UNSET) {
+               loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
+               loglevel_value = 0;
+       } else if (er_status == LTTNG_EVENT_RULE_STATUS_OK) {
+               lttng_log_level_rule_to_loglevel(log_level_rule, &loglevel_type, &loglevel_value);
+       } else {
+               abort();
        }
 
        return agent_find_event(name, loglevel_type, loglevel_value,
@@ -1419,8 +1424,8 @@ void agent_destroy(struct agent *agt)
  */
 int agent_app_ht_alloc(void)
 {
-       agent_apps_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
-       return agent_apps_ht_by_sock ? 0 : -1;
+       the_agent_apps_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+       return the_agent_apps_ht_by_sock ? 0 : -1;
 }
 
 /*
@@ -1457,11 +1462,12 @@ void agent_app_ht_clean(void)
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
 
-       if (!agent_apps_ht_by_sock) {
+       if (!the_agent_apps_ht_by_sock) {
                return;
        }
        rcu_read_lock();
-       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, node, node) {
+       cds_lfht_for_each_entry(
+                       the_agent_apps_ht_by_sock->ht, &iter.iter, node, node) {
                struct agent_app *app;
 
                app = caa_container_of(node, struct agent_app, node);
@@ -1469,7 +1475,7 @@ void agent_app_ht_clean(void)
        }
        rcu_read_unlock();
 
-       lttng_ht_destroy(agent_apps_ht_by_sock);
+       lttng_ht_destroy(the_agent_apps_ht_by_sock);
 }
 
 /*
@@ -1530,8 +1536,8 @@ void agent_update(const struct agent *agt, const struct agent_app *app)
  */
 int agent_by_event_notifier_domain_ht_create(void)
 {
-       trigger_agents_ht_by_domain = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
-       return trigger_agents_ht_by_domain ? 0 : -1;
+       the_trigger_agents_ht_by_domain = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
+       return the_trigger_agents_ht_by_domain ? 0 : -1;
 }
 
 /*
@@ -1542,24 +1548,24 @@ void agent_by_event_notifier_domain_ht_destroy(void)
        struct lttng_ht_node_u64 *node;
        struct lttng_ht_iter iter;
 
-       if (!trigger_agents_ht_by_domain) {
+       if (!the_trigger_agents_ht_by_domain) {
                return;
        }
 
        rcu_read_lock();
-       cds_lfht_for_each_entry (trigger_agents_ht_by_domain->ht, &iter.iter,
-                       node, node) {
+       cds_lfht_for_each_entry(the_trigger_agents_ht_by_domain->ht,
+                       &iter.iter, node, node) {
                struct agent *agent =
                                caa_container_of(node, struct agent, node);
                const int ret = lttng_ht_del(
-                               trigger_agents_ht_by_domain, &iter);
+                               the_trigger_agents_ht_by_domain, &iter);
 
                assert(ret == 0);
                agent_destroy(agent);
        }
 
        rcu_read_unlock();
-       lttng_ht_destroy(trigger_agents_ht_by_domain);
+       lttng_ht_destroy(the_trigger_agents_ht_by_domain);
 }
 
 struct agent *agent_find_by_event_notifier_domain(
@@ -1570,12 +1576,12 @@ struct agent *agent_find_by_event_notifier_domain(
        struct lttng_ht_iter iter;
        const uint64_t key = (uint64_t) domain_type;
 
-       assert(trigger_agents_ht_by_domain);
+       assert(the_trigger_agents_ht_by_domain);
 
        DBG3("Per-event notifier domain agent lookup for domain '%s'",
                        lttng_domain_type_str(domain_type));
 
-       lttng_ht_lookup(trigger_agents_ht_by_domain, &key, &iter);
+       lttng_ht_lookup(the_trigger_agents_ht_by_domain, &key, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (!node) {
                goto end;
This page took 0.026886 seconds and 4 git commands to generate.