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

Lennart Poettering lennart at kemper.freedesktop.org
Mon Nov 11 07:27:19 PST 2013


 src/libsystemd-bus/bus-message.c      |   76 +++++++++++++++++++++++++++++++++-
 src/libsystemd-bus/libsystemd-bus.sym |    2 
 src/systemd/sd-bus.h                  |    3 +
 3 files changed, 80 insertions(+), 1 deletion(-)

New commits:
commit 938bcbab125298b9c49946ca0bd0b47890e4d140
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 16:26:12 2013 +0100

    bus: add APIs for adding iovecs to messages as string or arrays

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 1a50226..b26d446 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -1498,7 +1498,11 @@ _public_ int sd_bus_message_append_basic(sd_bus_message *m, char type, const voi
         return message_append_basic(m, type, p, NULL);
 }
 
-_public_ int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s) {
+_public_ int sd_bus_message_append_string_space(
+                sd_bus_message *m,
+                size_t size,
+                char **s) {
+
         struct bus_container *c;
         void *a;
 
@@ -1543,6 +1547,40 @@ _public_ int sd_bus_message_append_string_space(sd_bus_message *m, size_t size,
         return 0;
 }
 
+_public_ int sd_bus_message_append_string_iovec(
+                sd_bus_message *m,
+                const struct iovec *iov,
+                unsigned n) {
+
+        size_t size;
+        unsigned i;
+        char *p;
+        int r;
+
+        assert_return(m, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(iov || n == 0, -EINVAL);
+        assert_return(!m->poisoned, -ESTALE);
+
+        size = IOVEC_TOTAL_SIZE(iov, n);
+
+        r = sd_bus_message_append_string_space(m, size, &p);
+        if (r < 0)
+                return r;
+
+        for (i = 0; i < n; i++) {
+
+                if (iov[i].iov_base)
+                        memcpy(p, iov[i].iov_base, iov[i].iov_len);
+                else
+                        memset(p, ' ', iov[i].iov_len);
+
+                p += iov[i].iov_len;
+        }
+
+        return 0;
+}
+
 static int bus_message_open_array(
                 sd_bus_message *m,
                 struct bus_container *c,
@@ -2159,6 +2197,42 @@ _public_ int sd_bus_message_append_array(sd_bus_message *m,
         return 0;
 }
 
+_public_ int sd_bus_message_append_array_iovec(
+                sd_bus_message *m,
+                char type,
+                const struct iovec *iov,
+                unsigned n) {
+
+        size_t size;
+        unsigned i;
+        void *p;
+        int r;
+
+        assert_return(m, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(bus_type_is_trivial(type), -EINVAL);
+        assert_return(iov || n == 0, -EINVAL);
+        assert_return(!m->poisoned, -ESTALE);
+
+        size = IOVEC_TOTAL_SIZE(iov, n);
+
+        r = sd_bus_message_append_array_space(m, type, size, &p);
+        if (r < 0)
+                return r;
+
+        for (i = 0; i < n; i++) {
+
+                if (iov[i].iov_base)
+                        memcpy(p, iov[i].iov_base, iov[i].iov_len);
+                else
+                        memset(p, 0, iov[i].iov_len);
+
+                p = (uint8_t*) p + iov[i].iov_len;
+        }
+
+        return 0;
+}
+
 _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
                                                char type,
                                                sd_memfd *memfd) {
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 4924cf1..2c4f07d 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -119,8 +119,10 @@ global:
         sd_bus_message_append_basic;
         sd_bus_message_append_array;
         sd_bus_message_append_array_space;
+        sd_bus_message_append_array_iovec;
         sd_bus_message_append_array_memfd;
         sd_bus_message_append_string_space;
+        sd_bus_message_append_string_iovec;
         sd_bus_message_append_string_memfd;
         sd_bus_message_append_strv;
         sd_bus_message_open_container;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index f843c77..6202acb 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -24,6 +24,7 @@
 
 #include <inttypes.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 
 #include "sd-id128.h"
 #include "sd-event.h"
@@ -186,8 +187,10 @@ 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_array_iovec(sd_bus_message *m, char type, const struct iovec *iov, unsigned n);
 int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, sd_memfd *memfd);
 int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s);
+int sd_bus_message_append_string_iovec(sd_bus_message *m, const struct iovec *iov, unsigned n);
 int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd* memfd);
 int sd_bus_message_append_strv(sd_bus_message *m, char **l);
 int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);



More information about the systemd-commits mailing list