chiark / gitweb /
sd-bus: reuse the KDBUS_CMD_FREE wrapper wherever appropriate
[elogind.git] / src / libsystemd / sd-bus / bus-message.c
index 6bf39cef6b3174812fbe921993ccde0bbc8b0a1d..3f2d6e74c525b5628ceb7a6b6724814f799b2e41 100644 (file)
@@ -129,13 +129,8 @@ static void message_free(sd_bus_message *m) {
 
         message_reset_parts(m);
 
-        if (m->release_kdbus) {
-                struct kdbus_cmd_free cmd_free = { };
-
-                cmd_free.flags = 0;
-                cmd_free.offset = (uint8_t *)m->kdbus - (uint8_t *)m->bus->kdbus_buffer;
-                (void) ioctl(m->bus->input_fd, KDBUS_CMD_FREE, &cmd_free);
-        }
+        if (m->release_kdbus)
+                bus_kernel_cmd_free(m->bus, (uint8_t *) m->kdbus - (uint8_t *) m->bus->kdbus_buffer);
 
         if (m->free_kdbus)
                 free(m->kdbus);
@@ -423,19 +418,19 @@ int bus_message_from_header(
 
         if (ucred) {
                 m->creds.pid = ucred->pid;
-                m->creds.uid = ucred->uid;
-                m->creds.gid = ucred->gid;
+                m->creds.euid = ucred->uid;
+                m->creds.egid = ucred->gid;
 
                 /* Due to namespace translations some data might be
                  * missing from this ucred record. */
                 if (m->creds.pid > 0)
                         m->creds.mask |= SD_BUS_CREDS_PID;
 
-                if (m->creds.uid != UID_INVALID)
-                        m->creds.mask |= SD_BUS_CREDS_UID;
+                if (m->creds.euid != UID_INVALID)
+                        m->creds.mask |= SD_BUS_CREDS_EUID;
 
-                if (m->creds.gid != GID_INVALID)
-                        m->creds.mask |= SD_BUS_CREDS_GID;
+                if (m->creds.egid != GID_INVALID)
+                        m->creds.mask |= SD_BUS_CREDS_EGID;
         }
 
         if (label) {
@@ -753,6 +748,24 @@ _public_ int sd_bus_message_new_method_errnof(
         return sd_bus_message_new_method_error(call, m, &berror);
 }
 
+void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
+        assert(bus);
+        assert(m);
+
+        m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus.Local";
+        m->creds.well_known_names_local = true;
+        m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+}
+
+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;
+}
+
 int bus_message_new_synthetic_error(
                 sd_bus *bus,
                 uint64_t cookie,
@@ -795,6 +808,8 @@ int bus_message_new_synthetic_error(
 
         t->error._need_free = -1;
 
+        bus_message_set_sender_driver(bus, t);
+
         *m = t;
         return 0;
 
@@ -1350,7 +1365,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;
 
@@ -1543,7 +1558,7 @@ _public_ int sd_bus_message_append_string_space(
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;
 
@@ -2329,8 +2344,7 @@ int bus_message_append_ap(
                 }
 
                 case SD_BUS_TYPE_INT64:
-                case SD_BUS_TYPE_UINT64:
-                case SD_BUS_TYPE_DOUBLE: {
+                case SD_BUS_TYPE_UINT64: {
                         uint64_t x;
 
                         x = va_arg(ap, uint64_t);
@@ -2338,6 +2352,14 @@ int bus_message_append_ap(
                         break;
                 }
 
+                case SD_BUS_TYPE_DOUBLE: {
+                        double x;
+
+                        x = va_arg(ap, double);
+                        r = sd_bus_message_append_basic(m, *t, &x);
+                        break;
+                }
+
                 case SD_BUS_TYPE_STRING:
                 case SD_BUS_TYPE_OBJECT_PATH:
                 case SD_BUS_TYPE_SIGNATURE: {
@@ -2697,7 +2719,7 @@ _public_ int sd_bus_message_append_string_memfd(
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;