]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
bus/containers: Shut down container servers when initiator goes away
authorSimon McVittie <smcv@collabora.com>
Thu, 22 Jun 2017 17:47:03 +0000 (18:47 +0100)
committerSimon McVittie <smcv@collabora.com>
Tue, 12 Dec 2017 16:22:34 +0000 (16:22 +0000)
We will eventually want to have other ways to signal that a
container server should stop listening, so that the container manager
doesn't have to stay on D-Bus (fd-passing the read end of a pipe
whose write end will be closed by the container manager has been
suggested as easier to deal with for Flatpak/Bubblewrap), but for
now we're doing the simplest possible thing.

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

bus/connection.c
bus/containers.c
bus/containers.h

index 53605fa3ad7a4a36a496336198e6667364779e51..d53522f5e6b9e583d93a0efc83d4237a723d9a50 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <config.h>
 #include "connection.h"
+
+#include "containers.h"
 #include "dispatch.h"
 #include "policy.h"
 #include "services.h"
@@ -306,6 +308,9 @@ bus_connection_disconnected (DBusConnection *connection)
       d->link_in_monitors = NULL;
     }
 
+  bus_containers_remove_connection (bus_context_get_containers (d->connections->context),
+                                    connection);
+
   if (d->link_in_connection_list != NULL)
     {
       if (d->name != NULL)
index 23193ac7acabe10137cf9e899ee5e633dae250ef..e30feb37b5a9b1c79568478a45ac060e9f2b7794 100644 (file)
@@ -812,3 +812,41 @@ bus_containers_stop_listening (BusContainers *self)
 }
 
 #endif /* DBUS_ENABLE_CONTAINERS */
+
+void
+bus_containers_remove_connection (BusContainers *self,
+                                  DBusConnection *connection)
+{
+#ifdef DBUS_ENABLE_CONTAINERS
+  BusContainerCreatorData *creator_data;
+
+  dbus_connection_ref (connection);
+  creator_data = dbus_connection_get_data (connection,
+                                           container_creator_data_slot);
+
+  if (creator_data != NULL)
+    {
+      DBusList *iter;
+      DBusList *next;
+
+      for (iter = _dbus_list_get_first_link (&creator_data->instances);
+           iter != NULL;
+           iter = next)
+        {
+          BusContainerInstance *instance = iter->data;
+
+          /* Remember where we got to before we do something that might free
+           * iter and instance */
+          next = _dbus_list_get_next_link (&creator_data->instances, iter);
+
+          _dbus_assert (instance->creator == connection);
+
+          /* This will invalidate iter and instance if there are no open
+           * connections to this instance */
+          bus_container_instance_stop_listening (instance);
+        }
+    }
+
+  dbus_connection_unref (connection);
+#endif /* DBUS_ENABLE_CONTAINERS */
+}
index 9a7ac0ba3cc2bc898e80ad07fe525ccb702741b3..e51d6ba125ec054803d0a1c174e6e2a914b92852 100644 (file)
@@ -39,6 +39,9 @@ dbus_bool_t bus_containers_handle_add_server          (DBusConnection  *connecti
 dbus_bool_t bus_containers_supported_arguments_getter (BusContext      *context,
                                                        DBusMessageIter *var_iter);
 
+void        bus_containers_remove_connection          (BusContainers *self,
+                                                       DBusConnection *connection);
+
 static inline void
 bus_clear_containers (BusContainers **containers_p)
 {