Add base support for event rule hit
[lttng-tools.git] / src / common / event-rule / syscall.c
index 826953c21fe6cc965bc1064a8434f0ebea412112..51f22fcc0ff85602d680f5216d790dc48f1c38a8 100644 (file)
@@ -6,11 +6,14 @@
  */
 
 #include <assert.h>
+#include <common/credentials.h>
 #include <common/error.h>
 #include <common/macros.h>
 #include <common/payload.h>
 #include <common/payload-view.h>
 #include <common/runas.h>
+#include <common/hashtable/hashtable.h>
+#include <common/hashtable/utils.h>
 #include <lttng/event-rule/event-rule-internal.h>
 #include <lttng/event-rule/syscall-internal.h>
 
@@ -137,7 +140,8 @@ end:
 }
 
 static enum lttng_error_code lttng_event_rule_syscall_generate_filter_bytecode(
-               struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+               struct lttng_event_rule *rule,
+               const struct lttng_credentials *creds)
 {
        int ret;
        enum lttng_error_code ret_code = LTTNG_OK;
@@ -177,7 +181,7 @@ static enum lttng_error_code lttng_event_rule_syscall_generate_filter_bytecode(
        }
 
        ret = run_as_generate_filter_bytecode(
-                       syscall->internal_filter.filter, uid, gid, &bytecode);
+                       syscall->internal_filter.filter, creds, &bytecode);
        if (ret) {
                ret_code = LTTNG_ERR_FILTER_INVAL;
        }
@@ -221,6 +225,25 @@ lttng_event_rule_syscall_generate_exclusions(
        return NULL;
 }
 
+static unsigned long
+lttng_event_rule_syscall_hash(
+               const struct lttng_event_rule *rule)
+{
+       unsigned long hash;
+       struct lttng_event_rule_syscall *syscall_rule =
+                       container_of(rule, typeof(*syscall_rule), parent);
+
+       hash = hash_key_ulong((void *) LTTNG_EVENT_RULE_TYPE_SYSCALL,
+                       lttng_ht_seed);
+       hash ^= hash_key_str(syscall_rule->pattern, lttng_ht_seed);
+       if (syscall_rule->filter_expression) {
+               hash ^= hash_key_str(syscall_rule->filter_expression,
+                               lttng_ht_seed);
+       }
+
+       return hash;
+}
+
 struct lttng_event_rule *lttng_event_rule_syscall_create()
 {
        struct lttng_event_rule *rule = NULL;
@@ -246,6 +269,7 @@ struct lttng_event_rule *lttng_event_rule_syscall_create()
                        lttng_event_rule_syscall_get_internal_filter_bytecode;
        syscall_rule->parent.generate_exclusions =
                        lttng_event_rule_syscall_generate_exclusions;
+       syscall_rule->parent.hash = lttng_event_rule_syscall_hash;
 end:
        return rule;
 }
This page took 0.024303 seconds and 4 git commands to generate.