From 7671f53cf3b6029a3bf00e502a0a58ac7a82e378 Mon Sep 17 00:00:00 2001 From: Christian Babeux Date: Thu, 23 Aug 2012 22:05:12 -0400 Subject: [PATCH] Notify the user if a filter is already enabled When using the enable-event command in conjunction with the --filter option, a user can specify a filter expression to refine the trace output. As stated in the lttng(1) man page, only the first activation of a filter on an event will work. Subsequent activation of any filter expression on the same event will fail. e.g: > lttng enable-event app:tp -s session -u --filter 'somefield > 42' Case: invalid filter expression > lttng enable-event app:tp -s session -u --filter 'invalid expression' Error: Error setting filter Warning: Some command(s) went wrong > ... Case: filter already enabled for event app:tp > lttng enable-event app:tp -s session -u --filter 'someotherfield < 42' Error: Error setting filter Warning: Some command(s) went wrong This commit differentiate the case where a filter was already set for the specified event from the generic 'Error setting filter' error message. e.g: > lttng enable-event app:tp -s session -u --filter 'somefield > 42' Case: invalid filter expression > lttng enable-event app:tp -s session -u --filter 'invalid expression' Error: Error setting filter Warning: Some command(s) went wrong > ... Case: filter already enabled for event app:tp > lttng enable-event app:tp -s session -u --filter 'someotherfield < 42' Error: Filter on event app:tp is already enabled (channel 0, session session) Warning: Some command(s) went wrong Acked-by: Mathieu Desnoyers Signed-off-by: Christian Babeux Signed-off-by: David Goulet --- src/bin/lttng/commands/enable_events.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 5a22c9513..90172e50a 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -384,7 +384,17 @@ static int enable_events(char *session_name) ret = lttng_set_event_filter(handle, ev.name, channel_name, opt_filter); if (ret < 0) { - ERR("Error setting filter"); + switch (-ret) { + case LTTNG_ERR_FILTER_EXIST: + ERR("Filter on events is already enabled" + " (channel %s, session %s)", + channel_name, session_name); + break; + default: + ERR("Error setting filter"); + break; + } + ret = -1; goto error; } @@ -554,7 +564,17 @@ static int enable_events(char *session_name) ret = lttng_set_event_filter(handle, ev.name, channel_name, opt_filter); if (ret < 0) { - ERR("Error setting filter"); + switch (-ret) { + case LTTNG_ERR_FILTER_EXIST: + ERR("Filter on event %s is already enabled" + " (channel %s, session %s)", + event_name, channel_name, session_name); + break; + default: + ERR("Error setting filter"); + break; + } + ret = -1; goto error; } -- 2.34.1