From 702cc1a2d95707d58907f6cd040d6d2171e8410b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Jul 2017 20:51:53 +0100 Subject: [PATCH] bus/containers: Indicate in loginfo whether connection is contained Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- bus/connection.c | 26 ++++++++++++++++++++++++++ bus/containers.c | 29 +++++++++++++++++++++++++++++ bus/containers.h | 4 ++++ 3 files changed, 59 insertions(+) diff --git a/bus/connection.c b/bus/connection.c index 4d6c4e43..1b5b4917 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -588,6 +588,9 @@ cache_peer_loginfo_string (BusConnectionData *d, unsigned long pid; char *windows_sid = NULL, *security_label = NULL; dbus_bool_t prev_added; + const char *container = NULL; + const char *container_type = NULL; + const char *container_name = NULL; if (!_dbus_string_init (&loginfo_buf)) return FALSE; @@ -659,6 +662,29 @@ cache_peer_loginfo_string (BusConnectionData *d, prev_added = TRUE; } + if (bus_containers_connection_is_contained (connection, &container, + &container_type, + &container_name)) + { + dbus_bool_t did_append; + + if (prev_added) + { + if (!_dbus_string_append_byte (&loginfo_buf, ' ')) + goto oom; + } + + did_append = _dbus_string_append_printf (&loginfo_buf, + "container=%s %s=\"%s\")", + container, + container_type, + container_name); + if (!did_append) + goto oom; + else + prev_added = TRUE; + } + if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string))) goto oom; diff --git a/bus/containers.c b/bus/containers.c index d6f1312d..412fe531 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -1089,3 +1089,32 @@ bus_containers_remove_connection (BusContainers *self, dbus_connection_unref (connection); #endif /* DBUS_ENABLE_CONTAINERS */ } + +dbus_bool_t +bus_containers_connection_is_contained (DBusConnection *connection, + const char **path, + const char **type, + const char **name) +{ +#ifdef DBUS_ENABLE_CONTAINERS + BusContainerInstance *instance; + + instance = dbus_connection_get_data (connection, contained_data_slot); + + if (instance != NULL) + { + if (path != NULL) + *path = instance->path; + + if (type != NULL) + *type = instance->type; + + if (name != NULL) + *name = instance->name; + + return TRUE; + } +#endif /* DBUS_ENABLE_CONTAINERS */ + + return FALSE; +} diff --git a/bus/containers.h b/bus/containers.h index f3ecf1d4..2fb4b3aa 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -49,6 +49,10 @@ dbus_bool_t bus_containers_supported_arguments_getter (BusContext *context, void bus_containers_remove_connection (BusContainers *self, DBusConnection *connection); +dbus_bool_t bus_containers_connection_is_contained (DBusConnection *connection, + const char **path, + const char **type, + const char **name); static inline void bus_clear_containers (BusContainers **containers_p) -- 2.13.3