From 2f7f7e16c0aa497fb50b12ab71ae79d3bd3805eb Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Wed, 26 Jun 2013 11:18:11 +0800 Subject: [PATCH 3/3] dbus-monitor: keep backwards compatibility eavesdropping as a match rule key introduced in DBus 1.5.6, and the privous implementation doesn't keep backwards compatibility with older dbus-daemon. And the reference dbus-daemon implementation just fail if unknwon key found in match rule, this is undined hehavior in DBus Sepcification. Also there is a feature request for change this hehavior to "ignore unknown key in match rule" See https://bugs.freedesktop.org/show_bug.cgi?id=66114 Signed-off-by: Chengwei Yang --- tools/dbus-monitor.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index 32e7e62..81268a0 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -377,15 +377,29 @@ main (int argc, char *argv[]) if (numFilters) { + int offset = 0; +fallback: for (i = 0; i < j; i++) { - dbus_bus_add_match (connection, filters[i], &error); + dbus_bus_add_match (connection, filters[i] + offset, &error); if (dbus_error_is_set (&error)) { - fprintf (stderr, "Failed to setup match \"%s\": %s\n", - filters[i], error.message); - dbus_error_free (&error); - exit (1); + /* eavesdropping introduces in D-Bus 1.5.6, + * to compatible with older dbus-daemon, fall back + */ + if (i == 0 && offset == 0) + { + offset = strlen (EAVESDROPPING_RULE) + 1; + dbus_error_free (&error); + goto fallback; + } + else + { + fprintf (stderr, "Failed to setup match \"%s\": %s\n", + filters[i], error.message); + dbus_error_free (&error); + exit (1); + } } free(filters[i]); } @@ -396,7 +410,14 @@ main (int argc, char *argv[]) EAVESDROPPING_RULE, &error); if (dbus_error_is_set (&error)) - goto lose; + { + dbus_error_free (&error); + dbus_bus_add_match (connection, + "", + &error); + if (dbus_error_is_set (&error)) + goto lose; + } } if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) { -- 1.7.9.5