From 7d31d92400bab9648016136da1b1e8c5cff1bfcf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 27 Nov 2014 02:57:22 +0100 Subject: [PATCH] sd-bus: unify logic how we patch the message source of driver messages --- src/libsystemd/sd-bus/bus-kernel.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 9349c1d79d5..3a3ed200a07 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -348,6 +348,15 @@ fail: return r; } +static void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m) { + assert(bus); + assert(m); + + m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus"; + m->creds.well_known_names_driver = true; + m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask; +} + static void unset_memfds(struct sd_bus_message *m) { struct bus_body_part *part; unsigned i; @@ -737,11 +746,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { } /* Override information from the user header with data from the kernel */ - if (k->src_id == KDBUS_SRC_ID_KERNEL) { - m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus"; - m->creds.well_known_names_driver = true; - m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask; - } else { + if (k->src_id == KDBUS_SRC_ID_KERNEL) + bus_message_set_sender_driver(bus, m); + else { snprintf(m->sender_buffer, sizeof(m->sender_buffer), ":1.%llu", (unsigned long long) k->src_id); m->sender = m->creds.unique_name = m->sender_buffer; } @@ -1075,9 +1082,7 @@ static int push_name_owner_changed(sd_bus *bus, const char *name, const char *ol if (r < 0) return r; - m->sender = "org.freedesktop.DBus"; - m->creds.well_known_names_driver = true; - m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask; + bus_message_set_sender_driver(bus, m); r = bus_seal_synthetic_message(bus, m); if (r < 0) @@ -1146,9 +1151,7 @@ static int translate_reply(sd_bus *bus, struct kdbus_msg *k, struct kdbus_item * if (r < 0) return r; - m->sender = "org.freedesktop.DBus"; - m->creds.well_known_names_driver = true; - m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask; + bus_message_set_sender_driver(bus, m); r = bus_seal_synthetic_message(bus, m); if (r < 0)