From 3288533a22edee51f21d87240f047104715fdc25 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 18:47:03 +0100 Subject: [PATCH 25/49] 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 --- bus/connection.c | 5 +++++ bus/containers.c | 38 ++++++++++++++++++++++++++++++++++++++ bus/containers.h | 2 ++ 3 files changed, 45 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 b3bdd7a5..b85956ad 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -712,3 +712,41 @@ bus_containers_unref (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 de946456..eb20599a 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -37,4 +37,6 @@ dbus_bool_t bus_containers_handle_add_container_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); #endif /* multiple-inclusion guard */ -- 2.11.0