gdbus: Work around a D-Bus bug with path_namespace='/' match rules
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Wed, 23 Oct 2013 14:07:46 +0000 (15:07 +0100)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Wed, 23 Oct 2013 14:36:23 +0000 (15:36 +0100)
D-Bus versions < 1.6.18 (i.e. all current versions) have a bug with the
path_namespace='/' match rule key. It should conceptually match everything,
but actually matches nothing. This results in no property change (or other)
signals being forwarded to the D-Bus client.

The work-around implemented in GDBusObjectManagerClient is to remove the
path_namespace match key if its value is ‘/’.

For the upstream D-Bus bug, see:
https://bugs.freedesktop.org/show_bug.cgi?id=70799

https://bugzilla.gnome.org/show_bug.cgi?id=710726

gio/gdbusobjectmanagerclient.c

index ed0adc0..d9ccf71 100644 (file)
@@ -1105,12 +1105,24 @@ subscribe_signals (GDBusObjectManagerClient *manager,
 
   if (name_owner != NULL)
     {
-      /* the bus daemon may not implement path_prefix so gracefully
-       * handle this by using a fallback
-       */
-      manager->priv->match_rule = g_strdup_printf ("type='signal',sender='%s',path_namespace='%s'",
-                                                   name_owner, manager->priv->object_path);
+      /* Only add path_namespace if it's non-'/'. This removes a no-op key from
+       * the match rule, and also works around a D-Bus bug where
+       * path_namespace='/' matches nothing in D-Bus versions < 1.6.18.
+       *
+       * See: https://bugs.freedesktop.org/show_bug.cgi?id=70799 */
+      if (g_str_equal (manager->priv->object_path, "/"))
+        {
+          manager->priv->match_rule = g_strdup_printf ("type='signal',sender='%s'",
+                                                       name_owner);
+        }
+      else
+        {
+          manager->priv->match_rule = g_strdup_printf ("type='signal',sender='%s',path_namespace='%s'",
+                                                       name_owner, manager->priv->object_path);
+        }
 
+      /* The bus daemon may not implement path_namespace so gracefully
+       * handle this by using a fallback triggered if @error is set. */
       ret = g_dbus_connection_call_sync (manager->priv->connection,
                                          "org.freedesktop.DBus",
                                          "/org/freedesktop/DBus",