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 undefined 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

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=66107
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
This commit is contained in:
Chengwei Yang 2013-10-09 10:44:12 +08:00 committed by Simon McVittie
parent b994830c7f
commit faaa092f20

View file

@ -367,26 +367,45 @@ main (int argc, char *argv[])
if (numFilters)
{
size_t offset = 0;
for (i = 0; i < j; i++)
{
dbus_bus_add_match (connection, filters[i], &error);
if (dbus_error_is_set (&error))
dbus_bus_add_match (connection, filters[i] + offset, &error);
if (dbus_error_is_set (&error) && i == 0 && offset == 0)
{
/* We might be talking to a pre-1.5.6 dbus-daemon
* which wouldn't understand eavesdrop=true.
* If this works, carry on with offset > 0
* on the remaining iterations. */
offset = strlen (EAVESDROPPING_RULE) + 1;
dbus_error_free (&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);
}
free(filters[i]);
free(filters[i]);
}
}
else
{
dbus_bus_add_match (connection,
EAVESDROPPING_RULE,
&error);
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)) {