From 90b24fde17a6c6bc5bde084806f612d4098a227d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2018 19:44:59 +0100 Subject: [PATCH 07/39] bus: Make bus_driver_send_name_owner_changed take DBusConnections All callers had access to the DBusConnection that is the old owner, and the DBusConnection that is the new owner. Pass those to the function instead of their names. This gives the function a bit more contextual information, which will be important when we filter NameOwnerChanged messages entering containers according to whether the container is allowed to see the connection. While I'm breaking its API anyway, rename the function to match the signal that it emits, which was renamed in early 2005. Signed-off-by: Simon McVittie --- bus/driver.c | 28 +++++++++++++++++----------- bus/driver.h | 10 +++++----- bus/services.c | 31 +++++++++++++++---------------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/bus/driver.c b/bus/driver.c index 8015f28b..d91c15f0 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -239,23 +239,29 @@ static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection, DBusError *error); dbus_bool_t -bus_driver_send_service_owner_changed (const char *service_name, - const char *old_owner, - const char *new_owner, - BusTransaction *transaction, - DBusError *error) +bus_driver_send_name_owner_changed (const char *service_name, + DBusConnection *old_owner, + DBusConnection *new_owner, + BusTransaction *transaction, + DBusError *error) { + const char *old_owner_name = ""; + const char *new_owner_name = ""; DBusMessage *message; dbus_bool_t retval; - const char *null_service; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - null_service = ""; + if (old_owner != NULL) + old_owner_name = bus_connection_get_name (old_owner); + + if (new_owner != NULL) + new_owner_name = bus_connection_get_name (new_owner); + _dbus_verbose ("sending name owner changed: %s [%s -> %s]\n", service_name, - old_owner ? old_owner : null_service, - new_owner ? new_owner : null_service); + old_owner_name, + new_owner_name); message = dbus_message_new_signal (DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -272,8 +278,8 @@ bus_driver_send_service_owner_changed (const char *service_name, if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &service_name, - DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service, - DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service, + DBUS_TYPE_STRING, &old_owner_name, + DBUS_TYPE_STRING, &new_owner_name, DBUS_TYPE_INVALID)) goto oom; diff --git a/bus/driver.h b/bus/driver.h index f127fd18..c9479da4 100644 --- a/bus/driver.h +++ b/bus/driver.h @@ -47,11 +47,11 @@ dbus_bool_t bus_driver_send_service_acquired (DBusConnection *connection, const char *service_name, BusTransaction *transaction, DBusError *error); -dbus_bool_t bus_driver_send_service_owner_changed (const char *service_name, - const char *old_owner, - const char *new_owner, - BusTransaction *transaction, - DBusError *error); +dbus_bool_t bus_driver_send_name_owner_changed (const char *service_name, + DBusConnection *old_owner, + DBusConnection *new_owner, + BusTransaction *transaction, + DBusError *error); dbus_bool_t bus_driver_generate_introspect_string (DBusString *xml, dbus_bool_t canonical_path, DBusMessage *message); diff --git a/bus/services.c b/bus/services.c index b7a4fdfd..1393361d 100644 --- a/bus/services.c +++ b/bus/services.c @@ -281,10 +281,10 @@ bus_registry_ensure (BusRegistry *registry, service_name, _dbus_string_get_const_data (service_name), service->name); - if (!bus_driver_send_service_owner_changed (service->name, - NULL, - bus_connection_get_name (owner_connection_if_created), - transaction, error)) + if (!bus_driver_send_name_owner_changed (service->name, + NULL, + owner_connection_if_created, + transaction, error)) { bus_service_unref (service); return NULL; @@ -1086,10 +1086,10 @@ bus_service_swap_owner (BusService *service, new_owner = (BusOwner *)link->data; new_owner_conn = new_owner->conn; - if (!bus_driver_send_service_owner_changed (service->name, - bus_connection_get_name (connection), - bus_connection_get_name (new_owner_conn), - transaction, error)) + if (!bus_driver_send_name_owner_changed (service->name, + connection, + new_owner_conn, + transaction, error)) return FALSE; /* This will be our new owner */ @@ -1161,10 +1161,9 @@ bus_service_remove_owner (BusService *service, } else if (_dbus_list_length_is_one (&service->owners)) { - if (!bus_driver_send_service_owner_changed (service->name, - bus_connection_get_name (connection), - NULL, - transaction, error)) + if (!bus_driver_send_name_owner_changed (service->name, + connection, NULL, + transaction, error)) return FALSE; } else @@ -1180,10 +1179,10 @@ bus_service_remove_owner (BusService *service, new_owner = (BusOwner *)link->data; new_owner_conn = new_owner->conn; - if (!bus_driver_send_service_owner_changed (service->name, - bus_connection_get_name (connection), - bus_connection_get_name (new_owner_conn), - transaction, error)) + if (!bus_driver_send_name_owner_changed (service->name, + connection, + new_owner_conn, + transaction, error)) return FALSE; /* This will be our new owner */ -- 2.17.0