From c0657016bbb98e1769edbaba8c00221f964c7402 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 14 Jun 2012 10:43:04 -0400 Subject: [PATCH] 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 --- doc/man/lttng.1 | 3 +++ src/bin/lttng-sessiond/event.c | 32 ++++++++++++++++++++++++ src/bin/lttng-sessiond/ust-app.c | 2 +- src/common/sessiond-comm/sessiond-comm.c | 1 + src/common/sessiond-comm/sessiond-comm.h | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/man/lttng.1 b/doc/man/lttng.1 index f13d5d341..ff3057626 100644 --- a/doc/man/lttng.1 +++ b/doc/man/lttng.1 @@ -645,6 +645,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 43caabf93..28b761dc5 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 6ad4a3775..a14131cda 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 4d31289a4..d37970797 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -159,6 +159,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 */ -- 2.34.1