diff options
author | Simon McVittie <smcv@collabora.com> | 2018-07-03 20:26:33 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2018-08-30 17:39:43 +0100 |
commit | 2798ecc45f91629fa75297e8de77594d7d83d957 (patch) | |
tree | 9c48be3abdf137e8fe83d1568f174f2b223c9fdd /bus/containers.c | |
parent | 64a6366027564b2bd046062bffc099b55caff0b7 (diff) | |
download | dbus-2798ecc45f91629fa75297e8de77594d7d83d957.tar.gz |
containers: Share code for what happens when we lose a connection
This improves test coverage, because
bus_container_instance_lost_connection() was previously only called
when we failed to set up a connection with a server due to OOM, but
it is now also called (instead of being duplicated) when we are told
to clean up a connection because it has disconnected.
To make sure that connections from containers can never cheat their
way into being treated as uncontained, do not set their
contained_data_slot to NULL.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
Diffstat (limited to 'bus/containers.c')
-rw-r--r-- | bus/containers.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/bus/containers.c b/bus/containers.c index ece12eab..5542e16b 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -482,7 +482,13 @@ bus_container_instance_lost_connection (BusContainerInstance *instance, if (_dbus_list_remove (&instance->connections, connection)) dbus_connection_unref (connection); - dbus_connection_set_data (connection, contained_data_slot, NULL, NULL); + /* We don't set connection's contained_data_slot to NULL, to make sure + * that once we have marked a connection as belonging to a container, + * there is no going back: even if we somehow keep a reference to it + * around, it will never be treated as uncontained. The connection's + * reference to the instance will be cleaned up on last-unref, and + * the list removal above ensures that the instance does not hold a + * circular ref to the connection, so the last-unref will happen. */ dbus_connection_unref (connection); bus_container_instance_unref (instance); @@ -1433,14 +1439,7 @@ bus_containers_remove_connection (BusContainers *self, instance = connection_get_instance (connection); if (instance != NULL) - { - bus_container_instance_ref (instance); - - if (_dbus_list_remove (&instance->connections, connection)) - dbus_connection_unref (connection); - - bus_container_instance_unref (instance); - } + bus_container_instance_lost_connection (instance, connection); dbus_connection_unref (connection); #endif /* DBUS_ENABLE_CONTAINERS */ |