chiark / gitweb /
sd-bus: unify logic how we patch the message source of driver messages
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 01:57:22 +0000 (02:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 21:02:12 +0000 (22:02 +0100)
src/libsystemd/sd-bus/bus-kernel.c

index 9349c1d..3a3ed20 100644 (file)
@@ -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)