Blob Blame History Raw
From d663f1b1a92a778bcdc68f29b8c08cb49431b4f7 Mon Sep 17 00:00:00 2001
From: Daniel Mack <daniel@zonque.org>
Date: Mon, 6 Oct 2014 18:36:16 +0200
Subject: [PATCH] sd-bus: sync kdbus.h (ABI break)

The KDBUS_CMD_FREE ioctl now uses a struct rather than a direct pointer
to the offset to free.

The KDBUS_CMD_MSG_CANCEL ioctl has also changes, but there's no user of
it yet in systemd.
---
 src/bus-proxyd/bus-proxyd.c         |  6 +++++-
 src/libsystemd/sd-bus/bus-control.c | 23 ++++++++++++++++++++---
 src/libsystemd/sd-bus/bus-kernel.c  |  7 +++++--
 src/libsystemd/sd-bus/kdbus.h       | 32 ++++++++++++++++++++++++++++++--
 4 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 5d58cd2af4..cbec04933c 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -730,6 +730,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ListQueuedOwners")) {
                 struct kdbus_cmd_name_list cmd = {};
                 struct kdbus_name_list *name_list;
+                struct kdbus_cmd_free cmd_free;
                 struct kdbus_cmd_name *name;
                 _cleanup_strv_free_ char **owners = NULL;
                 char *arg0;
@@ -773,7 +774,10 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
                         }
                 }
 
-                r = ioctl(a->input_fd, KDBUS_CMD_FREE, &cmd.offset);
+                cmd_free.flags = 0;
+                cmd_free.offset = cmd.offset;
+
+                r = ioctl(a->input_fd, KDBUS_CMD_FREE, &cmd_free);
                 if (r < 0)
                         return synthetic_reply_method_errno(m, r, NULL);
 
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index d9a53c702f..dbd94fc46b 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -223,6 +223,23 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
                 return bus_release_name_dbus1(bus, name);
 }
 
+static int kernel_cmd_free(sd_bus *bus, uint64_t offset)
+{
+        struct kdbus_cmd_free cmd;
+        int r;
+
+        assert(bus);
+
+        cmd.flags = 0;
+        cmd.offset = offset;
+
+        r = ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd);
+        if (r < 0)
+                return -errno;
+
+        return 0;
+}
+
 static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
         struct kdbus_cmd_name_list cmd = {};
         struct kdbus_name_list *name_list;
@@ -269,9 +286,9 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
                 }
         }
 
-        r = ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd.offset);
+        r = kernel_cmd_free(bus, cmd.offset);
         if (r < 0)
-                return -errno;
+                return r;
 
         return 0;
 }
@@ -597,7 +614,7 @@ static int bus_get_owner_kdbus(
         r = 0;
 
 fail:
-        ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd->offset);
+        kernel_cmd_free(bus, cmd->offset);
         return r;
 }
 
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 09ff25fe71..5ae1418afc 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -799,14 +799,17 @@ int bus_kernel_connect(sd_bus *b) {
 }
 
 static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
+        struct kdbus_cmd_free cmd;
         uint64_t off _alignas_(8);
         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;
+
+        ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd);
 
         KDBUS_ITEM_FOREACH(d, k, items) {
 
diff --git a/src/libsystemd/sd-bus/kdbus.h b/src/libsystemd/sd-bus/kdbus.h
index 801125946b..8994b5673d 100644
--- a/src/libsystemd/sd-bus/kdbus.h
+++ b/src/libsystemd/sd-bus/kdbus.h
@@ -444,6 +444,31 @@ struct kdbus_cmd_recv {
 } __attribute__((aligned(8)));
 
 /**
+ * struct kdbus_cmd_cancel - struct to cancel a synchronously pending message
+ * @cookie		The cookie of the pending message
+ * @flags		Flags for the free command. Currently unused.
+ *
+ * This struct is used with the KDBUS_CMD_CANCEL ioctl.
+ */
+struct kdbus_cmd_cancel {
+	__u64 cookie;
+	__u64 flags;
+} __attribute__((aligned(8)));
+
+/**
+ * struct kdbus_cmd_free - struct to free a slice of memory in the pool
+ * @offset		The offset of the memory slice, as returned by other
+ *			ioctls
+ * @flags		Flags for the free command. Currently unused.
+ *
+ * This struct is used with the KDBUS_CMD_FREE ioctl.
+ */
+struct kdbus_cmd_free {
+	__u64 offset;
+	__u64 flags;
+} __attribute__((aligned(8)));
+
+/**
  * enum kdbus_policy_access_type - permissions of a policy record
  * @_KDBUS_POLICY_ACCESS_NULL:	Uninitialized/invalid
  * @KDBUS_POLICY_ACCESS_USER:	Grant access to a uid
@@ -710,6 +735,7 @@ struct kdbus_conn_info {
  */
 struct kdbus_cmd_update {
 	__u64 size;
+	__u64 flags;
 	struct kdbus_item items[0];
 } __attribute__((aligned(8)));
 
@@ -807,8 +833,10 @@ enum kdbus_ioctl_type {
 					      struct kdbus_msg),
 	KDBUS_CMD_MSG_RECV =		_IOWR(KDBUS_IOCTL_MAGIC, 0x41,
 					      struct kdbus_cmd_recv),
-	KDBUS_CMD_MSG_CANCEL =		_IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
-	KDBUS_CMD_FREE =		_IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
+	KDBUS_CMD_MSG_CANCEL =		_IOW(KDBUS_IOCTL_MAGIC, 0x42,
+					     struct kdbus_cmd_cancel),
+	KDBUS_CMD_FREE =		_IOW(KDBUS_IOCTL_MAGIC, 0x43,
+					     struct kdbus_cmd_free),
 
 	KDBUS_CMD_NAME_ACQUIRE =	_IOWR(KDBUS_IOCTL_MAGIC, 0x50,
 					      struct kdbus_cmd_name),