chiark / gitweb /
sd-bus: sync kdbus.h (ABI break)
[elogind.git] / src / libsystemd / sd-bus / bus-kernel.c
index 0e74f9136accc44b74d4e66e93315e7e6650346d..c8340718988f25e67639bf99657e95cd7ab3a343 100644 (file)
@@ -332,6 +332,18 @@ fail:
         return r;
 }
 
+static void unset_memfds(struct sd_bus_message *m) {
+        struct bus_body_part *part;
+        unsigned i;
+
+        assert(m);
+
+        /* Make sure the memfds are not freed twice */
+        MESSAGE_FOREACH_PART(part, i, m)
+                if (part->memfd >= 0)
+                        part->memfd = -1;
+}
+
 static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         sd_bus_message *m = NULL;
         struct kdbus_item *d;
@@ -627,17 +639,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         return 1;
 
 fail:
-        if (m) {
-                struct bus_body_part *part;
-                unsigned i;
-
-                /* Make sure the memfds are not freed twice */
-                MESSAGE_FOREACH_PART(part, i, m)
-                        if (part->memfd >= 0)
-                                part->memfd = -1;
-
-                sd_bus_message_unref(m);
-        }
+        unset_memfds(m);
+        sd_bus_message_unref(m);
 
         return r;
 }
@@ -748,10 +751,9 @@ int bus_kernel_take_fd(sd_bus *b) {
                 }
         }
 
-        /* The higher 32bit of both flags fields are considered
+        /* The higher 32bit of the bus_flags fields are considered
          * 'incompatible flags'. Refuse them all for now. */
-        if (hello->bus_flags > 0xFFFFFFFFULL ||
-            hello->conn_flags > 0xFFFFFFFFULL)
+        if (hello->bus_flags > 0xFFFFFFFFULL)
                 return -ENOTSUP;
 
         if (!bloom_validate_parameters((size_t) hello->bloom.size, (unsigned) hello->bloom.n_hash))
@@ -796,14 +798,14 @@ int bus_kernel_connect(sd_bus *b) {
 }
 
 static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
-        uint64_t off _alignas_(8);
+        struct kdbus_cmd_free cmd;
         struct kdbus_item *d;
 
         assert(bus);
         assert(k);
 
-        off = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer;
-        ioctl(bus->input_fd, KDBUS_CMD_FREE, &off);
+        cmd.flags = 0;
+        cmd.offset = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer;
 
         KDBUS_ITEM_FOREACH(d, k, items) {
 
@@ -812,10 +814,13 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
                 else if (d->type == KDBUS_ITEM_PAYLOAD_MEMFD)
                         safe_close(d->memfd.fd);
         }
+
+        (void) ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd);
 }
 
 int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call) {
         int r;
+        uint64_t flags;
 
         assert(bus);
         assert(m);
@@ -838,7 +843,12 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
         if (hint_sync_call)
                 m->kdbus->flags |= KDBUS_MSG_FLAGS_EXPECT_REPLY|KDBUS_MSG_FLAGS_SYNC_REPLY;
 
+        /* The kernel will return the set of supported flags in m->kdbus->flags.
+         * Save the current message flags before issuing the ioctl, and restore them
+         * afterwards */
+        flags = m->kdbus->flags;
         r = ioctl(bus->output_fd, KDBUS_CMD_MSG_SEND, m->kdbus);
+        m->kdbus->flags = flags;
         if (r < 0) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                 sd_bus_message *reply;
@@ -1225,8 +1235,11 @@ int kdbus_translate_attach_flags(uint64_t mask, uint64_t *kdbus_mask) {
         if (mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID))
                 m |= KDBUS_ATTACH_CREDS;
 
-        if (mask & (SD_BUS_CREDS_COMM|SD_BUS_CREDS_TID_COMM))
-                m |= KDBUS_ATTACH_COMM;
+        if (mask & SD_BUS_CREDS_COMM)
+                m |= KDBUS_ATTACH_PID_COMM;
+
+        if (mask & SD_BUS_CREDS_TID_COMM)
+                m |= KDBUS_ATTACH_TID_COMM;
 
         if (mask & SD_BUS_CREDS_EXE)
                 m |= KDBUS_ATTACH_EXE;
@@ -1302,13 +1315,6 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
                 return -errno;
         }
 
-        /* The higher 32bit of the flags field are considered
-         * 'incompatible flags'. Refuse them all for now. */
-        if (make->flags > 0xFFFFFFFFULL) {
-                safe_close(fd);
-                return -ENOTSUP;
-        }
-
         if (s) {
                 char *p;
 
@@ -1434,24 +1440,21 @@ int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char *
         n->size = offsetof(struct kdbus_item, str) + strlen(ep_name) + 1;
         strcpy(n->str, ep_name);
 
-        if (ioctl(fd, KDBUS_CMD_EP_MAKE, make) < 0) {
+        if (ioctl(fd, KDBUS_CMD_ENDPOINT_MAKE, make) < 0) {
                 safe_close(fd);
                 return -errno;
         }
 
-        /* The higher 32bit of the flags field are considered
-         * 'incompatible flags'. Refuse them all for now. */
-        if (make->flags > 0xFFFFFFFFULL) {
-                safe_close(fd);
-                return -ENOTSUP;
-        }
-
         if (ep_path) {
-                int r = asprintf(ep_path, "%s/%s", dirname(path), ep_name);
-                if (r == -1 || !*ep_path) {
+                char *p;
+
+                p = strjoin(dirname(path), "/", ep_name, NULL);
+                if (!p) {
                         safe_close(fd);
                         return -ENOMEM;
                 }
+
+                *ep_path = p;
         }
 
         return fd;
@@ -1494,7 +1497,7 @@ int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) {
                 n = KDBUS_ITEM_NEXT(n);
         }
 
-        r = ioctl(fd, KDBUS_CMD_EP_UPDATE, update);
+        r = ioctl(fd, KDBUS_CMD_ENDPOINT_UPDATE, update);
         if (r < 0)
                 return -errno;
 
@@ -1565,10 +1568,9 @@ int bus_kernel_make_starter(
         if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0)
                 return -errno;
 
-        /* The higher 32bit of both flags fields are considered
+        /* The higher 32bit of the bus_flags fields are considered
          * 'incompatible flags'. Refuse them all for now. */
-        if (hello->bus_flags > 0xFFFFFFFFULL ||
-            hello->conn_flags > 0xFFFFFFFFULL)
+        if (hello->bus_flags > 0xFFFFFFFFULL)
                 return -ENOTSUP;
 
         if (!bloom_validate_parameters((size_t) hello->bloom.size, (unsigned) hello->bloom.n_hash))