From 1873c24287949d17388cab23566823778cc3eeb7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 18:47:03 +0100 Subject: [PATCH] bus/containers: Shut down container servers when initiator goes away 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 https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- bus/connection.c | 5 +++++ bus/containers.c | 38 ++++++++++++++++++++++++++++++++++++++ bus/containers.h | 3 +++ 3 files changed, 46 insertions(+) diff --git a/bus/connection.c b/bus/connection.c index 3fc62c78..4d6c4e43 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -23,6 +23,8 @@ #include #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) diff --git a/bus/containers.c b/bus/containers.c index 5cc69d9d..277c507b 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -810,3 +810,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 */ +} diff --git a/bus/containers.h b/bus/containers.h index 9a7ac0ba..e51d6ba1 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -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) { -- 2.13.3