]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
containers: Factor out connection_get_instance and make it NULL-safe
authorSimon McVittie <smcv@collabora.com>
Mon, 16 Apr 2018 18:35:59 +0000 (19:35 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 21 Jun 2018 16:42:16 +0000 (17:42 +0100)
When I introduce per-container message filtering, it'll be useful to
be able to get the instance for a connection without worrying about
whether that connection is NULL (representing the dbus-daemon itself,
or an activatable service that has not yet been activated).

Also make it robust against Containers having not been initialized,
for completeness.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656

bus/containers.c

index 038068e13e94df3a14be4f0b6f213ce6164e3f6b..ece12eab93975f5d3cf16ff3e8bbe79e9466c603 100644 (file)
@@ -1119,6 +1119,23 @@ failed:
   return FALSE;
 }
 
+/*
+ * This accepts a NULL connection so that it can be used when checking
+ * whether to allow sending or receiving a message, which might involve
+ * the dbus-daemon itself as a message sender or recipient.
+ */
+static BusContainerInstance *
+connection_get_instance (DBusConnection *connection)
+{
+  if (connection == NULL)
+    return NULL;
+
+  if (contained_data_slot == -1)
+    return NULL;
+
+  return dbus_connection_get_data (connection, contained_data_slot);
+}
+
 dbus_bool_t
 bus_containers_handle_get_connection_instance (DBusConnection *caller,
                                                BusTransaction *transaction,
@@ -1154,7 +1171,7 @@ bus_containers_handle_get_connection_instance (DBusConnection *caller,
         goto failed;
     }
 
-  instance = dbus_connection_get_data (subject, contained_data_slot);
+  instance = connection_get_instance (subject);
 
   if (instance == NULL)
     {
@@ -1413,7 +1430,7 @@ bus_containers_remove_connection (BusContainers *self,
         }
     }
 
-  instance = dbus_connection_get_data (connection, contained_data_slot);
+  instance = connection_get_instance (connection);
 
   if (instance != NULL)
     {
@@ -1438,7 +1455,7 @@ bus_containers_connection_is_contained (DBusConnection *connection,
 #ifdef DBUS_ENABLE_CONTAINERS
   BusContainerInstance *instance;
 
-  instance = dbus_connection_get_data (connection, contained_data_slot);
+  instance = connection_get_instance (connection);
 
   if (instance != NULL)
     {