summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-02-12 19:19:05 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-04-29 15:42:18 +0100
commit435ddb0df1bee02a690380ea1160ca98af764b8e (patch)
tree5658b858af7134a7b0e66877e2301b5bf50193ed
parent8e333e682aeb7be5ed63e5fbcc5eb0376ad9e59a (diff)
minotaur: bail if asked to monitor >1 bus
A coworker was just tripped up by `dbus-monitor --session --system` only monitoring the system bus. This patch would have saved him reproducing a tricky bug several times! Bug: https://bugs.freedesktop.org/show_bug.cgi?id=26548 Reviewed-by: Colin Walters <walters@verbum.org> Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--tools/dbus-monitor.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 3779368a..5edb5c0b 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -215,6 +215,21 @@ usage (char *name, int ecode)
exit (ecode);
}
+static void
+only_one_type (dbus_bool_t *seen_bus_type,
+ char *name)
+{
+ if (*seen_bus_type)
+ {
+ fprintf (stderr, "I only support monitoring one bus at a time!\n");
+ usage (name, 1);
+ }
+ else
+ {
+ *seen_bus_type = TRUE;
+ }
+}
+
static dbus_bool_t sigint_received = FALSE;
static void
@@ -231,6 +246,7 @@ main (int argc, char *argv[])
DBusBusType type = DBUS_BUS_SESSION;
DBusHandleMessageFunction filter_func = monitor_filter_func;
char *address = NULL;
+ dbus_bool_t seen_bus_type = FALSE;
int i = 0, j = 0, numFilters = 0;
char **filters = NULL;
@@ -251,19 +267,27 @@ main (int argc, char *argv[])
char *arg = argv[i];
if (!strcmp (arg, "--system"))
- type = DBUS_BUS_SYSTEM;
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+ type = DBUS_BUS_SYSTEM;
+ }
else if (!strcmp (arg, "--session"))
- type = DBUS_BUS_SESSION;
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+ type = DBUS_BUS_SESSION;
+ }
else if (!strcmp (arg, "--address"))
- {
- if (i+1 < argc)
- {
- address = argv[i+1];
- i++;
- }
- else
- usage (argv[0], 1);
- }
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+
+ if (i+1 < argc)
+ {
+ address = argv[i+1];
+ i++;
+ }
+ else
+ usage (argv[0], 1);
+ }
else if (!strcmp (arg, "--help"))
usage (argv[0], 0);
else if (!strcmp (arg, "--monitor"))