From 1035d0eba132b1d314d0040ba15bc288c077dee4 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Mon, 24 Jun 2013 14:50:59 +0800 Subject: [PATCH] dbus-monitor: --monitor can not be used with --profile There are two different output formats of dbus-monitor, specified by "--monitor" or "--profile" respectively, and only one of them can be taken. Currently, it doesn't fail if both of them were specified but just overwrite silently. This may misleading user. Signed-off-by: Chengwei Yang --- tools/dbus-monitor.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index a4b5478..58debec 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -245,7 +245,7 @@ main (int argc, char *argv[]) DBusConnection *connection; DBusError error; DBusBusType type = DBUS_BUS_SESSION; - DBusHandleMessageFunction filter_func = monitor_filter_func; + DBusHandleMessageFunction filter_func = NULL; char *address = NULL; dbus_bool_t seen_bus_type = FALSE; @@ -263,6 +263,16 @@ main (int argc, char *argv[]) setvbuf (stdout, NULL, _IOLBF, 0); #endif +#define set_filter_func(filter) do \ + { \ + if (filter_func) \ + { \ + fprintf (stderr, "\"--monitor\" can not be used with \"--profile\"\n"); \ + usage (argv[0], 1); \ + } \ + filter_func = filter; \ + } while (0) + for (i = 1; i < argc; i++) { char *arg = argv[i]; @@ -292,9 +302,9 @@ main (int argc, char *argv[]) else if (!strcmp (arg, "--help")) usage (argv[0], 0); else if (!strcmp (arg, "--monitor")) - filter_func = monitor_filter_func; + set_filter_func (monitor_filter_func); else if (!strcmp (arg, "--profile")) - filter_func = profile_filter_func; + set_filter_func (profile_filter_func); else if (!strcmp (arg, "--")) continue; else if (arg[0] == '-') @@ -318,6 +328,9 @@ main (int argc, char *argv[]) } } + if (filter_func == NULL) + filter_func = monitor_filter_func; + dbus_error_init (&error); if (address != NULL) -- 1.7.9.5