From: Mathieu Desnoyers Date: Thu, 14 Jun 2012 14:43:04 +0000 (-0400) Subject: Fix: enable event with different loglevel error X-Git-Tag: v2.1.0-rc1~111 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a027b2d2edced8011ef674f88146253715952af7;p=lttng-tools.git Fix: enable event with different loglevel error This following example was NOT returning a correct error message. "event1" is set with a loglevel "TRACE_CRIT". The normal behavior here is that once enabled, you can not change the loglevel of the enable event on the tracer side with a second command. It now returns a new error message like so: $ lttng enable-event event1 --loglevel-only TRACE-CRIT -u $ lttng enable-event event1 --loglevel-only TRACE-WARNING -u [...] Event already enabled with different loglevel This commit makes the session daemon verify if _both_ the name and loglevel are the same when enabling an event or else an error is returned. Also, the session daemon will continue enabling events and not return an error is the loglevel does not match event for ust app on the tracer which returns an EPERM at that stage. This is to address the case where two applications have the same event name but with different loglevel. Reported-by: Tan Dung Le Tran Signed-off-by: David Goulet Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/man/lttng.1 b/doc/man/lttng.1 index a74750e08..6bbf3154e 100644 --- a/doc/man/lttng.1 +++ b/doc/man/lttng.1 @@ -647,6 +647,9 @@ No UST consumer detected .IP "99" No Kernel consumer detected + +.IP "100" +Event already enabled with different loglevel .PP .SH "ENVIRONMENT VARIABLES" diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index c9c2f17f4..4bc8fb90d 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -45,6 +45,23 @@ 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) +{ + 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. */ @@ -395,8 +412,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; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 63b106ae4..956c5dafe 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -645,7 +645,7 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess, ret = ustctl_create_event(app->sock, &ua_event->attr, ua_chan->obj, &ua_event->obj); if (ret < 0) { - if (ret == -EEXIST) { + if (ret == -EEXIST || ret == -EPERM) { ret = 0; goto error; } diff --git a/src/common/sessiond-comm/sessiond-comm.c b/src/common/sessiond-comm/sessiond-comm.c index 891f532d6..706b8a7cd 100644 --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@ -125,6 +125,7 @@ static const char *lttcomm_readable_code[] = { [ LTTCOMM_ERR_INDEX(LTTCOMM_INVALID) ] = "Invalid parameter", [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_USTCONSUMERD) ] = "No UST consumer detected", [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_KERNCONSUMERD) ] = "No kernel consumer detected", + [ LTTCOMM_ERR_INDEX(LTTCOMM_EVENT_EXIST_LOGLEVEL) ] = "Event already enabled with different loglevel", }; /* diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index eb9ae8475..118353584 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -162,6 +162,7 @@ enum lttcomm_return_code { LTTCOMM_INVALID, /* Invalid parameter */ LTTCOMM_NO_USTCONSUMERD, /* No UST consumer detected */ LTTCOMM_NO_KERNCONSUMERD, /* No Kernel consumer detected */ + LTTCOMM_EVENT_EXIST_LOGLEVEL, /* Event already enabled with different loglevel */ /* MUST be last element */ LTTCOMM_NR, /* Last element */