Ignore exclusion names order when matching events
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.c
index b7ef806af1a5a218cdfa7ccc2f1b4c6e04691f98..1ddd597cf5647082a6eba147c32adab2cbb2aaa6 100644 (file)
@@ -15,7 +15,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
@@ -72,6 +71,7 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
        struct ltt_ust_event *event;
        const struct ltt_ust_ht_key *key;
        int ev_loglevel_value;
+       int ll_match;
 
        assert(node);
        assert(_key);
@@ -88,19 +88,11 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
        }
 
        /* Event loglevel value and type. */
-       if (event->attr.loglevel_type == key->loglevel_type) {
-               /* Same loglevel type. */
-               if (key->loglevel_type != LTTNG_UST_LOGLEVEL_ALL) {
-                       /*
-                        * Loglevel value must also match since the loglevel
-                        * type is not all.
-                        */
-                       if (ev_loglevel_value != key->loglevel_value) {
-                               goto no_match;
-                       }
-               }
-       } else {
-               /* Loglevel type is different: no match. */
+       ll_match = loglevels_match(event->attr.loglevel_type,
+               ev_loglevel_value, key->loglevel_type,
+               key->loglevel_value, LTTNG_UST_LOGLEVEL_ALL);
+
+       if (!ll_match) {
                goto no_match;
        }
 
@@ -124,12 +116,46 @@ int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key)
        }
 
        if (key->exclusion && event->exclusion) {
-               /* Both exclusions exist; check count followed by names. */
-               if (event->exclusion->count != key->exclusion->count ||
-                               memcmp(event->exclusion->names, key->exclusion->names,
-                                       event->exclusion->count * LTTNG_SYMBOL_NAME_LEN) != 0) {
+               size_t i;
+
+               /* Check exclusion counts first. */
+               if (event->exclusion->count != key->exclusion->count) {
                        goto no_match;
                }
+
+               /* Compare names individually. */
+               for (i = 0; i < event->exclusion->count; ++i) {
+                       size_t j;
+                       bool found = false;
+                       const char *name_ev =
+                               LTTNG_EVENT_EXCLUSION_NAME_AT(
+                                       event->exclusion, i);
+
+                       /*
+                        * Compare this exclusion name to all the key's
+                        * exclusion names.
+                        */
+                       for (j = 0; j < key->exclusion->count; ++j) {
+                               const char *name_key =
+                                       LTTNG_EVENT_EXCLUSION_NAME_AT(
+                                               key->exclusion, j);
+
+                               if (!strncmp(name_ev, name_key,
+                                               LTTNG_SYMBOL_NAME_LEN)) {
+                                       /* Names match! */
+                                       found = true;
+                                       break;
+                               }
+                       }
+
+                       /*
+                        * If the current exclusion name was not found amongst
+                        * the key's exclusion names, then there's no match.
+                        */
+                       if (!found) {
+                               goto no_match;
+                       }
+               }
        }
        /* Match. */
        return 1;
@@ -367,6 +393,39 @@ error:
        return luc;
 }
 
+/*
+ * Validates an exclusion list.
+ *
+ * Returns 0 if valid, negative value if invalid.
+ */
+static int validate_exclusion(struct lttng_event_exclusion *exclusion)
+{
+       size_t i;
+       int ret = 0;
+
+       assert(exclusion);
+
+       for (i = 0; i < exclusion->count; ++i) {
+               size_t j;
+               const char *name_a =
+                       LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, i);
+
+               for (j = 0; j < i; ++j) {
+                       const char *name_b =
+                               LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, j);
+
+                       if (!strncmp(name_a, name_b, LTTNG_SYMBOL_NAME_LEN)) {
+                               /* Match! */
+                               ret = -1;
+                               goto end;
+                       }
+               }
+       }
+
+end:
+       return ret;
+}
+
 /*
  * Allocate and initialize a ust event. Set name and event type.
  * We own filter_expression, filter, and exclusion.
@@ -383,6 +442,10 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
 
        assert(ev);
 
+       if (exclusion && validate_exclusion(exclusion)) {
+               goto error;
+       }
+
        lue = zmalloc(sizeof(struct ltt_ust_event));
        if (lue == NULL) {
                PERROR("ust event zmalloc");
This page took 0.02531 seconds and 4 git commands to generate.