omit standard match iff sender=org.freedesktop.DBus 41/84241/2
authorKonrad Lipinski <konrad.l@samsung.com>
Wed, 17 Aug 2016 12:27:55 +0000 (14:27 +0200)
committerKonrad Lipinski <konrad.l@samsung.com>
Thu, 18 Aug 2016 10:50:26 +0000 (12:50 +0200)
Change-Id: Ib8a1c138983124a2597b0c700f5c6a2c7dd4744e

dbus/dbus-transport-kdbus.c

index 2fa932e..b82e4d0 100644 (file)
@@ -1369,33 +1369,6 @@ strcmp_existing (const char *str1, const char *str2)
 }
 
 static dbus_bool_t
-kernel_match_needed (MatchRule *rule)
-{
-  int message_type;
-
-  /* Allow only NameOwnerChanged member */
-  if (strcmp_existing (_match_rule_get_member (rule), "NameOwnerChanged") != 0)
-    return FALSE;
-
-  /* Allow only signals */
-  message_type = _match_rule_get_message_type (rule);
-  if (message_type != DBUS_MESSAGE_TYPE_INVALID && message_type != DBUS_MESSAGE_TYPE_SIGNAL)
-    return FALSE;
-
-  /* Check if from DBus */
-  if (strcmp_existing (_match_rule_get_sender (rule), DBUS_SERVICE_DBUS) != 0)
-    return FALSE;
-
-  if (strcmp_existing (_match_rule_get_interface (rule), DBUS_INTERFACE_DBUS) != 0)
-    return FALSE;
-
-  if (strcmp_existing (_match_rule_get_path (rule), DBUS_PATH_DBUS) != 0)
-    return FALSE;
-
-  return TRUE;
-}
-
-static dbus_bool_t
 is_bloom_needed (MatchRule *rule)
 {
   int rule_int;
@@ -1511,6 +1484,7 @@ add_match_kdbus (DBusTransportKdbus *transport,
   int ret;
 
   rule_cookie = match_rule_get_cookie (rule);
+  rule_sender = _match_rule_get_sender (rule);
 
 /*
  * First check if it is org.freedesktop.DBus's NameOwnerChanged or any
@@ -1518,45 +1492,46 @@ add_match_kdbus (DBusTransportKdbus *transport,
  * because it must be converted to special kdbus rule (kdbus has separate rules
  * for kdbus (kernel) generated broadcasts).
  */
-  if (kernel_match_needed (rule))
+  if (!strcmp_existing (rule_sender, DBUS_SERVICE_DBUS))
     {
-      ret = _kdbus_add_match_name_change (transport->kdbus,
-                                          0,
-                                          rule_cookie,
-                                          KDBUS_MATCH_ID_ANY,
-                                          0,
-                                          KDBUS_MATCH_ID_ANY,
-                                          0);
-      if (0 != ret)
-        {
-          _dbus_verbose ("Failed adding match rule for name removal for daemon, error: %d, %s\n",
-                         ret, _dbus_strerror (ret));
-          return FALSE;
-        }
+      int message_type = _match_rule_get_message_type (rule);
 
-      ret = _kdbus_add_match_id_change (transport->kdbus,
-                                        0,
-                                        rule_cookie,
-                                        KDBUS_MATCH_ID_ANY,
-                                        0);
-      if (0 != ret)
+      if ((DBUS_MESSAGE_TYPE_INVALID == message_type || DBUS_MESSAGE_TYPE_SIGNAL == message_type)
+          && !strcmp_existing (_match_rule_get_member (rule), "NameOwnerChanged")
+          && !strcmp_existing (_match_rule_get_interface (rule), DBUS_INTERFACE_DBUS)
+          && !strcmp_existing (_match_rule_get_path (rule), DBUS_PATH_DBUS))
         {
-          _dbus_verbose ("Failed adding match rule for adding id for daemon, error: %d, %s\n",
-                         ret, _dbus_strerror (ret));
-          return FALSE;
-        }
+          ret = _kdbus_add_match_name_change (transport->kdbus,
+                                              0,
+                                              rule_cookie,
+                                              KDBUS_MATCH_ID_ANY,
+                                              0,
+                                              KDBUS_MATCH_ID_ANY,
+                                              0);
+          if (0 != ret)
+            {
+              _dbus_verbose ("Failed adding match rule for name removal for daemon, error: %d, %s\n",
+                             ret, _dbus_strerror (ret));
+              return FALSE;
+            }
 
-      _dbus_verbose ("Added match rule for kernel correctly.\n");
+          ret = _kdbus_add_match_id_change (transport->kdbus,
+                                            0,
+                                            rule_cookie,
+                                            KDBUS_MATCH_ID_ANY,
+                                            0);
+          if (0 != ret)
+            {
+              _dbus_verbose ("Failed adding match rule for adding id for daemon, error: %d, %s\n",
+                             ret, _dbus_strerror (ret));
+              return FALSE;
+            }
 
-/*
- * In case all of sender, interface and path are NULL, the rule
- * says simply about NameHasOwner signal from any object, any interface, any sender.
- * So, we need to consider that.
- * Otherwise, our job is finished here.
- */
-      if (_match_rule_get_sender (rule) != NULL
-          || _match_rule_get_interface (rule) != NULL
-          || _match_rule_get_path (rule) != NULL)
+          _dbus_verbose ("Added match rule for kernel correctly.\n");
+        }
+
+      /* Sender=DBUS_SERVICE_DBUS matches (as opposed to wildcard sender) need no standard rule. */
+      if (rule_sender)
         return TRUE;
     }
 
@@ -1567,7 +1542,6 @@ add_match_kdbus (DBusTransportKdbus *transport,
 
   need_bloom = is_bloom_needed (rule);
 
-  rule_sender = _match_rule_get_sender (rule);
   if (rule_sender != NULL)
     {
       DBusString str;