Fix: enable event loglevel match function
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
index 5a6825e6ef8a7412ec679bbb9f0c67cb95b12e7b..24dd292a4e3fdd5f86e48cf0ae11762938766694 100644 (file)
@@ -45,6 +45,32 @@ static void init_syscalls_kernel_event(struct lttng_event *event)
        event->type = LTTNG_EVENT_SYSCALL;
 }
 
+/*
+ * Return 1 if loglevels match or 0 on failure.
+ */
+static int loglevel_match(struct ltt_ust_event *uevent,
+               enum lttng_ust_loglevel_type log_type, int loglevel)
+{
+       /*
+        * For the loglevel type ALL, the loglevel is set to -1 but the event
+        * received by the session daemon is 0 which does not match the negative
+        * value in the existing event.
+        */
+       if (log_type == LTTNG_UST_LOGLEVEL_ALL) {
+               loglevel = -1;
+       }
+
+       if (uevent == NULL || uevent->attr.loglevel_type != log_type ||
+                       uevent->attr.loglevel != loglevel) {
+               goto no_match;
+       }
+
+       return 1;
+
+no_match:
+       return 0;
+}
+
 /*
  * Disable kernel tracepoint event for a channel from the kernel session.
  */
@@ -279,8 +305,7 @@ end:
 int event_ust_enable_all_tracepoints(struct ltt_ust_session *usess, int domain,
                struct ltt_ust_channel *uchan)
 {
-       int ret, i;
-       size_t size;
+       int ret, i, size;
        struct lttng_ht_iter iter;
        struct ltt_ust_event *uevent = NULL;
        struct lttng_event *events = NULL;
@@ -396,8 +421,23 @@ int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain,
                to_create = 1;
        }
 
+       /* Check loglevels */
+       ret = loglevel_match(uevent, event->loglevel_type, event->loglevel);
+       if (ret == 0) {
+               /*
+                * No match meaning that the user tried to enable a known event but
+                * with a different loglevel.
+                */
+               DBG("Enable event %s does not match existing event %s with loglevel "
+                               "respectively of %d and %d", event->name, uevent->attr.name,
+                               uevent->attr.loglevel, event->loglevel);
+               ret = LTTCOMM_EVENT_EXIST_LOGLEVEL;
+               goto error;
+       }
+
        if (uevent->enabled) {
                /* It's already enabled so everything is OK */
+               ret = LTTCOMM_OK;
                goto end;
        }
 
@@ -521,8 +561,7 @@ error:
 int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, int domain,
                struct ltt_ust_channel *uchan)
 {
-       int ret, i;
-       size_t size;
+       int ret, i, size;
        struct lttng_ht_iter iter;
        struct ltt_ust_event *uevent = NULL;
        struct lttng_event *events = NULL;
This page took 0.023743 seconds and 4 git commands to generate.