sessiond: use `loglevel_value` and `loglevel_type` names
[lttng-tools.git] / src / bin / lttng-sessiond / agent.c
index 7aaefdff28db06d6102a79476f3af05d33c64d57..f230c3619d43c9deae4c6d321e357194dc1b18b2 100644 (file)
@@ -117,9 +117,10 @@ static int ht_match_event(struct cds_lfht_node *node,
                goto no_match;
        }
 
-       if (event->loglevel != key->loglevel) {
+       if (event->loglevel_value != key->loglevel_value) {
                if (event->loglevel_type == LTTNG_EVENT_LOGLEVEL_ALL &&
-                               key->loglevel == 0 && event->loglevel == -1) {
+                               key->loglevel_value == 0 &&
+                               event->loglevel_value == -1) {
                        goto match;
                }
                goto no_match;
@@ -145,7 +146,7 @@ static void add_unique_agent_event(struct lttng_ht *ht,
        assert(event);
 
        key.name = event->name;
-       key.loglevel = event->loglevel;
+       key.loglevel_value = event->loglevel_value;
 
        node_ptr = cds_lfht_add_unique(ht->ht,
                        ht->hash_fct(event->node.key, lttng_ht_seed),
@@ -163,7 +164,7 @@ static void destroy_event_agent_rcu(struct rcu_head *head)
        struct agent_event *event =
                caa_container_of(node, struct agent_event, node);
 
-       free(event);
+       agent_destroy_event(event);
 }
 
 /*
@@ -378,7 +379,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event)
        }
 
        memset(&msg, 0, sizeof(msg));
-       msg.loglevel = event->loglevel;
+       msg.loglevel_value = event->loglevel_value;
        msg.loglevel_type = event->loglevel_type;
        strncpy(msg.name, event->name, sizeof(msg.name));
        ret = send_payload(app->sock, &msg, sizeof(msg));
@@ -789,9 +790,7 @@ void agent_add(struct agent *agt, struct lttng_ht *ht)
 
        DBG3("Agent adding from domain %d", agt->domain);
 
-       rcu_read_lock();
        lttng_ht_add_unique_u64(ht, &agt->node);
-       rcu_read_unlock();
 }
 
 /*
@@ -804,7 +803,7 @@ struct agent *agent_create(enum lttng_domain_type domain)
        int ret;
        struct agent *agt;
 
-       agt = zmalloc(sizeof(*agt));
+       agt = zmalloc(sizeof(struct agent));
        if (!agt) {
                goto error;
        }
@@ -822,33 +821,37 @@ error:
 }
 
 /*
- * Create a newly allocated agent event data structure. If name is valid, it's
- * copied into the created event.
+ * Create a newly allocated agent event data structure.
+ * Ownership of filter_expression is taken.
  *
  * Return a new object else NULL on error.
  */
 struct agent_event *agent_create_event(const char *name,
-               struct lttng_filter_bytecode *filter)
+               int loglevel_value, enum lttng_loglevel_type loglevel_type,
+               struct lttng_filter_bytecode *filter, char *filter_expression)
 {
-       struct agent_event *event;
+       struct agent_event *event = NULL;
 
        DBG3("Agent create new event with name %s", name);
 
-       event = zmalloc(sizeof(*event));
-       if (!event) {
+       if (!name) {
+               ERR("Failed to create agent event; no name provided.");
                goto error;
        }
 
-       if (name) {
-               strncpy(event->name, name, sizeof(event->name));
-               event->name[sizeof(event->name) - 1] = '\0';
-               lttng_ht_node_init_str(&event->node, event->name);
+       event = zmalloc(sizeof(*event));
+       if (!event) {
+               goto error;
        }
 
-       if (filter) {
-               event->filter = filter;
-       }
+       strncpy(event->name, name, sizeof(event->name));
+       event->name[sizeof(event->name) - 1] = '\0';
+       lttng_ht_node_init_str(&event->node, event->name);
 
+       event->loglevel_value = loglevel_value;
+       event->loglevel_type = loglevel_type;
+       event->filter = filter;
+       event->filter_expression = filter_expression;
 error:
        return event;
 }
@@ -863,10 +866,7 @@ void agent_add_event(struct agent_event *event, struct agent *agt)
        assert(agt->events);
 
        DBG3("Agent adding event %s", event->name);
-
-       rcu_read_lock();
        add_unique_agent_event(agt->events, event);
-       rcu_read_unlock();
        agt->being_used = 1;
 }
 
@@ -914,7 +914,7 @@ error:
  *
  * Return object if found else NULL.
  */
-struct agent_event *agent_find_event(const char *name, int loglevel,
+struct agent_event *agent_find_event(const char *name, int loglevel_value,
                struct agent *agt)
 {
        struct lttng_ht_node_str *node;
@@ -928,7 +928,7 @@ struct agent_event *agent_find_event(const char *name, int loglevel,
 
        ht = agt->events;
        key.name = name;
-       key.loglevel = loglevel;
+       key.loglevel_value = loglevel_value;
 
        cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed),
                        ht_match_event, &key, &iter.iter);
@@ -956,12 +956,12 @@ void agent_destroy_event(struct agent_event *event)
 
        free(event->filter);
        free(event->filter_expression);
+       free(event->exclusion);
        free(event);
 }
 
 /*
- * Destroy an agent completely. Note that the given pointer is NOT freed
- * thus a reference to static or stack data can be passed to this function.
+ * Destroy an agent completely.
  */
 void agent_destroy(struct agent *agt)
 {
@@ -972,14 +972,6 @@ void agent_destroy(struct agent *agt)
 
        DBG3("Agent destroy");
 
-       /*
-        * Just ignore if no events hash table exists. This is possible if for
-        * instance an agent object was allocated but not initialized.
-        */
-       if (!agt->events) {
-               return;
-       }
-
        rcu_read_lock();
        cds_lfht_for_each_entry(agt->events->ht, &iter.iter, node, node) {
                int ret;
@@ -1000,6 +992,7 @@ void agent_destroy(struct agent *agt)
        rcu_read_unlock();
 
        ht_cleanup_push(agt->events);
+       free(agt);
 }
 
 /*
This page took 0.02681 seconds and 4 git commands to generate.