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 <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
This commit is contained in:
Simon McVittie 2017-06-22 18:47:03 +01:00
parent ee029b8370
commit 3048c90ccb
3 changed files with 46 additions and 0 deletions

View 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)

View 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 */
}

View 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)
{