[systemd-commits] 2 commits - src/libsystemd-bus src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Thu May 9 18:38:17 PDT 2013


 src/libsystemd-bus/bus-internal.h     |    2 
 src/libsystemd-bus/bus-kernel.c       |  168 +++++++++++++++++++---------------
 src/libsystemd-bus/bus-message.c      |   64 ++++++++++++
 src/libsystemd-bus/bus-message.h      |    3 
 src/libsystemd-bus/kdbus.h            |   35 ++++---
 src/libsystemd-bus/test-bus-kernel.c  |    3 
 src/libsystemd-bus/test-bus-marshal.c |    9 +
 src/systemd/sd-bus.h                  |    9 -
 8 files changed, 205 insertions(+), 88 deletions(-)

New commits:
commit fd8d62d94016d1981f65b9414af2218250fba070
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 10 03:36:55 2013 +0200

    bus: catch up with latest kdbus

diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 4babfac..05184fd 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -150,6 +150,8 @@ struct sd_bus {
 
         uint64_t hello_serial;
         unsigned iteration_counter;
+
+        void *kdbus_buffer;
 };
 
 static inline void bus_unrefp(sd_bus **b) {
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 0762b78..aecf408 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -25,6 +25,7 @@
 
 #include <fcntl.h>
 #include <malloc.h>
+#include <sys/mman.h>
 
 #include "util.h"
 
@@ -44,6 +45,8 @@
 #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
 #define KDBUS_ITEM_SIZE(s) ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE)
 
+#define KDBUS_BUFFER_SIZE (4*1024*1024)
+
 static int parse_unique_name(const char *s, uint64_t *id) {
         int r;
 
@@ -111,7 +114,7 @@ static void append_fds(struct kdbus_item **d, const int fds[], unsigned n_fds) {
 
         *d = ALIGN8_PTR(*d);
         (*d)->size = offsetof(struct kdbus_item, fds) + sizeof(int) * n_fds;
-        (*d)->type = KDBUS_MSG_UNIX_FDS;
+        (*d)->type = KDBUS_MSG_FDS;
         memcpy((*d)->fds, fds, sizeof(int) * n_fds);
 
         *d = (struct kdbus_item *) ((uint8_t*) *d + (*d)->size);
@@ -275,17 +278,12 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) {
 }
 
 int bus_kernel_take_fd(sd_bus *b) {
-        struct kdbus_cmd_hello hello = {
-                .conn_flags =
-                        KDBUS_HELLO_ACCEPT_FD|
-                        KDBUS_HELLO_ATTACH_COMM|
-                        KDBUS_HELLO_ATTACH_EXE|
-                        KDBUS_HELLO_ATTACH_CMDLINE|
-                        KDBUS_HELLO_ATTACH_CGROUP|
-                        KDBUS_HELLO_ATTACH_CAPS|
-                        KDBUS_HELLO_ATTACH_SECLABEL|
-                        KDBUS_HELLO_ATTACH_AUDIT
-        };
+        uint8_t h[ALIGN8(sizeof(struct kdbus_cmd_hello)) +
+                  ALIGN8(KDBUS_ITEM_HEADER_SIZE) +
+                  ALIGN8(sizeof(struct kdbus_vec))] = {};
+
+        struct kdbus_cmd_hello *hello = (struct kdbus_cmd_hello*) h;
+
         int r;
 
         assert(b);
@@ -293,20 +291,44 @@ int bus_kernel_take_fd(sd_bus *b) {
         if (b->is_server)
                 return -EINVAL;
 
-        r = ioctl(b->input_fd, KDBUS_CMD_HELLO, &hello);
+        if (!b->kdbus_buffer) {
+                b->kdbus_buffer = mmap(NULL, KDBUS_BUFFER_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+                if (b->kdbus_buffer == MAP_FAILED) {
+                        b->kdbus_buffer = NULL;
+                        return -errno;
+                }
+        }
+
+        hello->size = sizeof(h);
+        hello->conn_flags =
+                KDBUS_HELLO_ACCEPT_FD|
+                KDBUS_HELLO_ATTACH_COMM|
+                KDBUS_HELLO_ATTACH_EXE|
+                KDBUS_HELLO_ATTACH_CMDLINE|
+                KDBUS_HELLO_ATTACH_CGROUP|
+                KDBUS_HELLO_ATTACH_CAPS|
+                KDBUS_HELLO_ATTACH_SECLABEL|
+                KDBUS_HELLO_ATTACH_AUDIT;
+
+        hello->items[0].type = KDBUS_HELLO_BUFFER;
+        hello->items[0].size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec);
+        hello->items[0].vec.address = (uint64_t) b->kdbus_buffer;
+        hello->items[0].vec.size = KDBUS_BUFFER_SIZE;
+
+        r = ioctl(b->input_fd, KDBUS_CMD_HELLO, hello);
         if (r < 0)
                 return -errno;
 
         /* The higher 32bit of both 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 ||
+            hello->conn_flags > 0xFFFFFFFFULL)
                 return -ENOTSUP;
 
-        if (hello.bloom_size != BLOOM_SIZE)
+        if (hello->bloom_size != BLOOM_SIZE)
                 return -ENOTSUP;
 
-        if (asprintf(&b->unique_name, ":1.%llu", (unsigned long long) hello.id) < 0)
+        if (asprintf(&b->unique_name, ":1.%llu", (unsigned long long) hello->id) < 0)
                 return -ENOMEM;
 
         b->is_kernel = true;
@@ -356,18 +378,36 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m) {
         return 1;
 }
 
-static void close_kdbus_msg(struct kdbus_msg *k) {
+static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
         struct kdbus_item *d;
 
+        assert(bus);
+        assert(k);
+
+        ioctl(bus->input_fd, KDBUS_CMD_MSG_RELEASE, k);
+
         KDBUS_ITEM_FOREACH(d, k) {
 
-                if (d->type != KDBUS_MSG_UNIX_FDS)
+                if (d->type != KDBUS_MSG_FDS)
                         continue;
 
                 close_many(d->fds, (d->size - offsetof(struct kdbus_item, fds)) / sizeof(int));
         }
 }
 
+static bool range_contains(size_t astart, size_t asize, size_t bstart, size_t bsize, void *a, void **b) {
+
+        if (bstart < astart)
+                return false;
+
+        if (bstart + bsize > astart + asize)
+                return false;
+
+        *b = (uint8_t*) a + (bstart - astart);
+
+        return true;
+}
+
 static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_message **ret) {
         sd_bus_message *m = NULL;
         struct kdbus_item *d;
@@ -390,19 +430,19 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
 
                 l = d->size - offsetof(struct kdbus_item, data);
 
-                if (d->type == KDBUS_MSG_PAYLOAD) {
+                if (d->type == KDBUS_MSG_PAYLOAD_VEC) {
 
                         if (!h) {
-                                if (l < sizeof(struct bus_header))
+                                if (d->vec.size < sizeof(struct bus_header))
                                         return -EBADMSG;
 
-                                h = (struct bus_header*) d->data;
+                                h = (struct bus_header*) d->vec.address;
                         }
 
                         n_payload++;
-                        n_bytes += l;
+                        n_bytes += d->vec.size;
 
-                } else if (d->type == KDBUS_MSG_UNIX_FDS) {
+                } else if (d->type == KDBUS_MSG_FDS) {
                         int *f;
                         unsigned j;
 
@@ -431,6 +471,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
         if (n_bytes != total)
                 return -EBADMSG;
 
+        if (n_payload > 2)
+                return -EBADMSG;
+
         r = bus_message_from_header(h, sizeof(struct bus_header), fds, n_fds, NULL, seclabel, 0, &m);
         if (r < 0)
                 return r;
@@ -440,20 +483,13 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
 
                 l = d->size - offsetof(struct kdbus_item, data);
 
-                if (d->type == KDBUS_MSG_PAYLOAD) {
-
-                        if (idx == sizeof(struct bus_header) &&
-                            l == ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m)))
-                                m->fields = d->data;
-                        else if (idx == sizeof(struct bus_header) + ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m)) &&
-                                 l == BUS_MESSAGE_BODY_SIZE(m))
-                                m->body = d->data;
-                        else if (!(idx == 0 && l == sizeof(struct bus_header))) {
-                                sd_bus_message_unref(m);
-                                return -EBADMSG;
-                        }
+                if (d->type == KDBUS_MSG_PAYLOAD_VEC) {
+
+                        range_contains(idx, d->vec.size, ALIGN8(sizeof(struct bus_header)), BUS_MESSAGE_FIELDS_SIZE(m), (void*) d->vec.address, &m->fields);
+                        range_contains(idx, d->vec.size, ALIGN8(sizeof(struct bus_header)) + ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m)), BUS_MESSAGE_BODY_SIZE(m), (void*) d->vec.address, &m->body);
+
+                        idx += d->vec.size;
 
-                        idx += l;
                 } else if (d->type == KDBUS_MSG_SRC_CREDS) {
                         m->pid_starttime = d->creds.starttime / NSEC_PER_USEC;
                         m->uid = d->creds.uid;
@@ -480,10 +516,18 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
                 else if (d->type == KDBUS_MSG_SRC_CAPS) {
                         m->capability = d->data;
                         m->capability_size = l;
-                } else
+                } else if (d->type != KDBUS_MSG_FDS &&
+                           d->type != KDBUS_MSG_DST_NAME &&
+                           d->type != KDBUS_MSG_SRC_SECLABEL)
                         log_debug("Got unknown field from kernel %llu", d->type);
         }
 
+        if ((BUS_MESSAGE_FIELDS_SIZE(m) > 0 && !m->fields) ||
+            (BUS_MESSAGE_BODY_SIZE(m) > 0 && !m->body)) {
+                sd_bus_message_unref(m);
+                return -EBADMSG;
+        }
+
         r = bus_message_parse_fields(m);
         if (r < 0) {
                 sd_bus_message_unref(m);
@@ -509,7 +553,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
 
         /* We take possession of the kmsg struct now */
         m->kdbus = k;
-        m->free_kdbus = true;
+        m->bus = sd_bus_ref(bus);
+        m->release_kdbus = true;
         m->free_fds = true;
 
         fds = NULL;
@@ -520,48 +565,31 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess
 
 int bus_kernel_read_message(sd_bus *bus, sd_bus_message **m) {
         struct kdbus_msg *k;
-        size_t sz = 1024;
         int r;
 
         assert(bus);
         assert(m);
 
-        for (;;) {
-                void *q;
-
-                q = memalign(8, sz);
-                if (!q)
-                        return -errno;
-
-                free(bus->rbuffer);
-                k = bus->rbuffer = q;
-                k->size = sz;
-
-                /* Let's tell valgrind that there's really no need to
-                 * initialize this fully. This should be removed again
-                 * when valgrind learned the kdbus ioctls natively. */
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-                VALGRIND_MAKE_MEM_DEFINED(k, sz);
-#endif
-
-                r = ioctl(bus->input_fd, KDBUS_CMD_MSG_RECV, bus->rbuffer);
-                if (r >= 0)
-                        break;
-
+        r = ioctl(bus->input_fd, KDBUS_CMD_MSG_RECV, &k);
+        if (r < 0) {
                 if (errno == EAGAIN)
                         return 0;
 
-                if (errno != ENOBUFS)
-                        return -errno;
-
-                sz *= 2;
+                return -errno;
         }
 
+
+/*                 /\* Let's tell valgrind that there's really no need to */
+/*                  * initialize this fully. This should be removed again */
+/*                  * when valgrind learned the kdbus ioctls natively. *\/ */
+/* #ifdef HAVE_VALGRIND_MEMCHECK_H */
+/*                 VALGRIND_MAKE_MEM_DEFINED(k, sz); */
+/* #endif */
+
+
         r = bus_kernel_make_message(bus, k, m);
-        if (r > 0)
-                bus->rbuffer = NULL;
-        else
-                close_kdbus_msg(k);
+        if (r <= 0)
+                close_kdbus_msg(bus, k);
 
         return r < 0 ? r : 1;
 }
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index fdc3ac6..cc2b78a 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -66,11 +66,17 @@ static void message_free(sd_bus_message *m) {
         if (m->free_kdbus)
                 free(m->kdbus);
 
+        if (m->release_kdbus)
+                ioctl(m->bus->input_fd, KDBUS_CMD_MSG_RELEASE, m->kdbus);
+
         if (m->free_fds) {
                 close_many(m->fds, m->n_fds);
                 free(m->fds);
         }
 
+        if (m->bus)
+                sd_bus_unref(m->bus);
+
         free(m->cmdline_array);
 
         reset_containers(m);
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index eafbb7c..86a41a7 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -53,6 +53,8 @@ struct bus_header {
 struct sd_bus_message {
         unsigned n_ref;
 
+        sd_bus *bus;
+
         uint32_t reply_serial;
 
         const char *path;
@@ -81,6 +83,7 @@ struct sd_bus_message {
         bool free_body:1;
         bool free_kdbus:1;
         bool free_fds:1;
+        bool release_kdbus:1;
 
         struct bus_header *header;
         void *fields;
diff --git a/src/libsystemd-bus/kdbus.h b/src/libsystemd-bus/kdbus.h
index db5e243..a2eba18 100644
--- a/src/libsystemd-bus/kdbus.h
+++ b/src/libsystemd-bus/kdbus.h
@@ -70,14 +70,15 @@ enum {
 	KDBUS_MSG_NULL,
 
 	/* Filled in by userspace */
-	KDBUS_MSG_PAYLOAD,		/* .data, inline memory */
 	KDBUS_MSG_PAYLOAD_VEC,		/* .data_vec, reference to memory area */
-	KDBUS_MSG_UNIX_FDS,		/* .data_fds of file descriptors */
+	KDBUS_MSG_PAYLOAD_MEMFD,	/* file descriptor of a special data file */
+	KDBUS_MSG_FDS,			/* .data_fds of file descriptors */
 	KDBUS_MSG_BLOOM,		/* for broadcasts, carries bloom filter blob in .data */
 	KDBUS_MSG_DST_NAME,		/* destination's well-known name, in .str */
+	KDBUS_MSG_PRIORITY,		/* queue priority for message */
 
 	/* Filled in by kernelspace */
-	KDBUS_MSG_SRC_NAMES	= 0x200,/* NUL separated string list with well-known names of source */
+	KDBUS_MSG_SRC_NAMES	= 0x400,/* NUL separated string list with well-known names of source */
 	KDBUS_MSG_TIMESTAMP,		/* .timestamp */
 	KDBUS_MSG_SRC_CREDS,		/* .creds */
 	KDBUS_MSG_SRC_PID_COMM,		/* optional, in .str */
@@ -90,7 +91,7 @@ enum {
 	KDBUS_MSG_SRC_AUDIT,		/* .audit */
 
 	/* Special messages from kernel, consisting of one and only one of these data blocks */
-	KDBUS_MSG_NAME_ADD	= 0x400,/* .name_change */
+	KDBUS_MSG_NAME_ADD	= 0x800,/* .name_change */
 	KDBUS_MSG_NAME_REMOVE,		/* .name_change */
 	KDBUS_MSG_NAME_CHANGE,		/* .name_change */
 	KDBUS_MSG_ID_ADD,		/* .id_change */
@@ -99,14 +100,14 @@ enum {
 	KDBUS_MSG_REPLY_DEAD,		/* dito */
 };
 
-enum {
-	KDBUS_VEC_ALIGNED		= 1 <<  0,
-};
-
 struct kdbus_vec {
 	__u64 address;
 	__u64 size;
-	__u64 flags;
+};
+
+struct kdbus_memfd {
+	__u64 size;
+	int fd;
 };
 
 /**
@@ -137,6 +138,7 @@ struct kdbus_item {
 		struct kdbus_timestamp timestamp;
 
 		/* specific fields */
+		int fd;
 		int fds[0];
 		struct kdbus_manager_msg_name_change name_change;
 		struct kdbus_manager_msg_id_change id_change;
@@ -236,6 +238,8 @@ enum {
 /* Items to append to struct kdbus_cmd_hello */
 enum {
 	KDBUS_HELLO_NULL,
+	KDBUS_HELLO_BUFFER,	/* kdbus_vec, userspace supplied buffer to
+				 * place received messages */
 };
 
 struct kdbus_cmd_hello {
@@ -276,7 +280,7 @@ enum {
 				 * cgroup membership paths * to messages. */
 	KDBUS_MAKE_CRED,	/* allow translator services which connect
 				 * to the bus on behalf of somebody else,
-				 * allow specifying the credentials of the
+				 * allow specifiying the credentials of the
 				 * client to connect on behalf on. Needs
 				 * privileges */
 };
@@ -401,7 +405,8 @@ enum kdbus_cmd {
 
 	/* kdbus ep node commands: require connected state */
 	KDBUS_CMD_MSG_SEND =		_IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
-	KDBUS_CMD_MSG_RECV =		_IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
+	KDBUS_CMD_MSG_RECV =		_IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg *),
+	KDBUS_CMD_MSG_RELEASE =		_IOWR(KDBUS_IOC_MAGIC, 0x42, struct kdbus_msg),
 
 	KDBUS_CMD_NAME_ACQUIRE =	_IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
 	KDBUS_CMD_NAME_RELEASE =	_IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
@@ -414,5 +419,13 @@ enum kdbus_cmd {
 
 	/* kdbus ep node commands: require ep owner state */
 	KDBUS_CMD_EP_POLICY_SET =	_IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),
+
+	/* kdbus ep node commands: */
+	KDBUS_CMD_MEMFD_NEW =		_IOWR(KDBUS_IOC_MAGIC, 0x80, int *),
+
+	/* kdbus memfd commands: */
+	KDBUS_CMD_MEMFD_SIZE_GET =	_IOWR(KDBUS_IOC_MAGIC, 0x81, __u64 *),
+	KDBUS_CMD_MEMFD_SEAL_GET =	_IOWR(KDBUS_IOC_MAGIC, 0x82, int *),
+	KDBUS_CMD_MEMFD_SEAL_SET =	_IOWR(KDBUS_IOC_MAGIC, 0x83, int),
 };
 #endif
diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c
index 1095e57..72514a3 100644
--- a/src/libsystemd-bus/test-bus-kernel.c
+++ b/src/libsystemd-bus/test-bus-kernel.c
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 
 #include "util.h"
+#include "log.h"
 
 #include "sd-bus.h"
 #include "bus-message.h"
@@ -36,6 +37,8 @@ int main(int argc, char *argv[]) {
         sd_bus *a, *b;
         int r, pipe_fds[2];
 
+        log_set_max_level(LOG_DEBUG);
+
         bus_ref = bus_kernel_create("deine-mutter", &bus_name);
         if (bus_ref == -ENOENT)
                 return EXIT_TEST_SKIP;

commit f8e013f8bf476e6d61fb2e218c85e23032a46302
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 10 01:12:15 2013 +0200

    bus: add sd_bus_message_append_string_space() for zero-copy string appending

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index afd4551..fdc3ac6 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -1207,6 +1207,60 @@ int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p) {
         return message_append_basic(m, type, p, NULL);
 }
 
+int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s) {
+        struct bus_container *c;
+        char *e;
+        void *a;
+        int r;
+
+        if (!m)
+                return -EINVAL;
+        if (!s)
+                return -EINVAL;
+        if (m->sealed)
+                return -EPERM;
+
+        c = message_get_container(m);
+
+        if (c->signature && c->signature[c->index]) {
+                /* Container signature is already set */
+
+                if (c->signature[c->index] != SD_BUS_TYPE_STRING)
+                        return -ENXIO;
+        } else {
+                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                if (c->enclosing != 0)
+                        return -ENXIO;
+
+                e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRING), NULL);
+                if (!e)
+                        return -ENOMEM;
+        }
+
+
+        a = message_extend_body(m, 4, 4 + size + 1);
+        if (!a) {
+                r = -ENOMEM;
+                goto fail;
+        }
+
+        *(uint32_t*) a = size;
+        *s = (char*) a + 4;
+
+        (*s)[size] = 0;
+
+        if (c->enclosing != SD_BUS_TYPE_ARRAY)
+                c->index++;
+
+        return 0;
+
+fail:
+        if (e)
+                c->signature[c->index] = 0;
+
+        return r;
+}
+
 static int bus_message_open_array(
                 sd_bus_message *m,
                 struct bus_container *c,
@@ -1799,7 +1853,7 @@ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
         return r;
 }
 
-int sd_bus_message_append_array_ptr(sd_bus_message *m, char type, size_t size, void **ptr) {
+int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size, void **ptr) {
         ssize_t align, sz;
         void *a;
         int r;
@@ -1851,7 +1905,7 @@ int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, s
         if (!ptr && size > 0)
                 return -EINVAL;
 
-        r = sd_bus_message_append_array_ptr(m, type, size, &p);
+        r = sd_bus_message_append_array_space(m, type, size, &p);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index ac51953..ef1a77f 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -44,6 +44,7 @@ int main(int argc, char *argv[]) {
         size_t sz;
         char *h;
         const int32_t integer_array[] = { -1, -2, 0, 1, 2 }, *return_array;
+        char *s;
 
         r = sd_bus_message_new_method_call(NULL, "foobar.waldo", "/", "foobar.waldo", "Piep", &m);
         assert_se(r >= 0);
@@ -78,6 +79,10 @@ int main(int argc, char *argv[]) {
         r = sd_bus_message_close_container(m);
         assert_se(r >= 0);
 
+        r = sd_bus_message_append_string_space(m, 5, &s);
+        assert_se(r >= 0);
+        strcpy(s, "hallo");
+
         r = sd_bus_message_append_array(m, 'i', integer_array, sizeof(integer_array));
         assert_se(r >= 0);
 
@@ -172,6 +177,10 @@ int main(int argc, char *argv[]) {
         assert_se(streq(x, "foobar"));
         assert_se(streq(y, "waldo"));
 
+        r = sd_bus_message_read_basic(m, 's', &s);
+        assert_se(r > 0);
+        assert_se(streq(s, "hallo"));
+
         r = sd_bus_message_read_array(m, 'i', (const void**) &return_array, &sz);
         assert_se(r > 0);
         assert_se(sz == sizeof(integer_array));
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 2dab93d..28c8536 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -158,21 +158,20 @@ int sd_bus_message_set_destination(sd_bus_message *m, const char *destination);
 
 int sd_bus_message_append(sd_bus_message *m, const char *types, ...);
 int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p);
+int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, size_t size);
+int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size, void **ptr);
+int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s);
 int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);
 int sd_bus_message_close_container(sd_bus_message *m);
 
 int sd_bus_message_read(sd_bus_message *m, const char *types, ...);
 int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p);
+int sd_bus_message_read_array(sd_bus_message *m, char type, const void **ptr, size_t *size);
 int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *contents);
 int sd_bus_message_exit_container(sd_bus_message *m);
 int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents);
 int sd_bus_message_rewind(sd_bus_message *m, int complete);
 
-int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, size_t size);
-int sd_bus_message_append_array_ptr(sd_bus_message *m, char type, size_t size, void **ptr);
-
-int sd_bus_message_read_array(sd_bus_message *m, char type, const void **ptr, size_t *size);
-
 /* Convenience calls */
 
 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);



More information about the systemd-commits mailing list