systemd: export message_append_cmdline

Change-Id: I337ebf4eda95597b59778c7f6198fa5388472c2e
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meta-phosphor/common/recipes-core/systemd/systemd/0001-Export-message_append_cmdline.patch b/meta-phosphor/common/recipes-core/systemd/systemd/0001-Export-message_append_cmdline.patch
new file mode 100644
index 0000000..afb2a48
--- /dev/null
+++ b/meta-phosphor/common/recipes-core/systemd/systemd/0001-Export-message_append_cmdline.patch
@@ -0,0 +1,323 @@
+From 5dfdd9973fe6437985d535fd530cec83a2774113 Mon Sep 17 00:00:00 2001
+From: Brad Bishop <bradleyb@us.ibm.com>
+Date: Tue, 16 Aug 2016 15:07:34 -0400
+Subject: [PATCH] Export message_append_cmdline
+
+Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
+---
+ Makefile.am                         |  43 ++++--
+ src/libsystemd/libsystemd.sym       |   1 +
+ src/libsystemd/sd-bus/bus-message.c | 254 ++++++++++++++++++++++++++++++++++++
+ src/systemd/sd-bus.h                |   1 +
+ 4 files changed, 285 insertions(+), 14 deletions(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index 03341fc..0dbf4b7 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -3032,7 +3033,10 @@ libsystemd_internal_la_SOURCES = \
+ 	src/libsystemd/sd-device/sd-device.c \
+ 	src/libsystemd/sd-device/device-private.c \
+ 	src/libsystemd/sd-device/device-private.h \
+-	src/libsystemd/sd-resolve/sd-resolve.c
++	src/libsystemd/sd-resolve/sd-resolve.c \
++	src/shared/bus-util.c \
++	src/shared/bus-util.h
++
+ 
+ libsystemd_internal_la_LIBADD = \
+ 	libbasic.la \
+diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
+index 4ab637b..f0c06c7 100644
+--- a/src/libsystemd/libsystemd.sym
++++ b/src/libsystemd/libsystemd.sym
+@@ -488,4 +488,5 @@ global:
+         sd_journal_has_persistent_files;
+         sd_journal_enumerate_fields;
+         sd_journal_restart_fields;
++        sd_bus_message_append_cmdline;
+ } LIBSYSTEMD_227;
+diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
+index c2e913f..d8d3ec8 100644
+--- a/src/libsystemd/sd-bus/bus-message.c
++++ b/src/libsystemd/sd-bus/bus-message.c
+@@ -38,6 +38,7 @@
+ #include "time-util.h"
+ #include "utf8.h"
+ #include "util.h"
++#include "parse-util.h"
+ 
+ static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
+ 
+@@ -5946,3 +5947,256 @@ _public_ int sd_bus_message_set_priority(sd_bus_message *m, int64_t priority) {
+         m->priority = priority;
+         return 0;
+ }
++
++_public_ int sd_bus_message_append_cmdline(sd_bus_message *m, const char *signature, char ***x) {
++        char **p;
++        int r;
++
++        assert(m);
++        assert(signature);
++        assert(x);
++
++        p = *x;
++
++        for (;;) {
++                const char *v;
++                char t;
++
++                t = *signature;
++                v = *p;
++
++                if (t == 0)
++                        break;
++                if (!v) {
++                        log_error("Too few parameters for signature.");
++                        return -EINVAL;
++                }
++
++                signature++;
++                p++;
++
++                switch (t) {
++
++                case SD_BUS_TYPE_BOOLEAN:
++
++                        r = parse_boolean(v);
++                        if (r < 0) {
++                                log_error("Failed to parse as boolean: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &r);
++                        break;
++
++                case SD_BUS_TYPE_BYTE: {
++                        uint8_t z;
++
++                        r = safe_atou8(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as byte (unsigned 8bit integer): %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_INT16: {
++                        int16_t z;
++
++                        r = safe_atoi16(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as signed 16bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_UINT16: {
++                        uint16_t z;
++
++                        r = safe_atou16(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as unsigned 16bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_INT32: {
++                        int32_t z;
++
++                        r = safe_atoi32(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as signed 32bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_UINT32: {
++                        uint32_t z;
++
++                        r = safe_atou32(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as unsigned 32bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_INT64: {
++                        int64_t z;
++
++                        r = safe_atoi64(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as signed 64bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_UINT64: {
++                        uint64_t z;
++
++                        r = safe_atou64(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as unsigned 64bit integer: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++
++                case SD_BUS_TYPE_DOUBLE: {
++                        double z;
++
++                        r = safe_atod(v, &z);
++                        if (r < 0) {
++                                log_error("Failed to parse as double precision floating point: %s", v);
++                                return r;
++                        }
++
++                        r = sd_bus_message_append_basic(m, t, &z);
++                        break;
++                }
++
++                case SD_BUS_TYPE_STRING:
++                case SD_BUS_TYPE_OBJECT_PATH:
++                case SD_BUS_TYPE_SIGNATURE:
++
++                        r = sd_bus_message_append_basic(m, t, v);
++                        break;
++
++                case SD_BUS_TYPE_ARRAY: {
++                        uint32_t n;
++                        size_t k;
++
++                        r = safe_atou32(v, &n);
++                        if (r < 0) {
++                                log_error("Failed to parse number of array entries: %s", v);
++                                return r;
++                        }
++
++                        r = signature_element_length(signature, &k);
++                        if (r < 0) {
++                                log_error("Invalid array signature.");
++                                return r;
++                        }
++
++                        {
++                                unsigned i;
++                                char s[k + 1];
++                                memcpy(s, signature, k);
++                                s[k] = 0;
++
++                                r = sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, s);
++                                if (r < 0)
++                                        return bus_log_create_error(r);
++
++                                for (i = 0; i < n; i++) {
++                                        r = sd_bus_message_append_cmdline(m, s, &p);
++                                        if (r < 0)
++                                                return r;
++                                }
++                        }
++
++                        signature += k;
++
++                        r = sd_bus_message_close_container(m);
++                        break;
++                }
++
++                case SD_BUS_TYPE_VARIANT:
++                        r = sd_bus_message_open_container(m, SD_BUS_TYPE_VARIANT, v);
++                        if (r < 0)
++                                return bus_log_create_error(r);
++
++                        r = sd_bus_message_append_cmdline(m, v, &p);
++                        if (r < 0)
++                                return r;
++
++                        r = sd_bus_message_close_container(m);
++                        break;
++
++                case SD_BUS_TYPE_STRUCT_BEGIN:
++                case SD_BUS_TYPE_DICT_ENTRY_BEGIN: {
++                        size_t k;
++
++                        signature--;
++                        p--;
++
++                        r = signature_element_length(signature, &k);
++                        if (r < 0) {
++                                log_error("Invalid struct/dict entry signature.");
++                                return r;
++                        }
++
++                        {
++                                char s[k-1];
++                                memcpy(s, signature + 1, k - 2);
++                                s[k - 2] = 0;
++
++                                r = sd_bus_message_open_container(m, t == SD_BUS_TYPE_STRUCT_BEGIN ? SD_BUS_TYPE_STRUCT : SD_BUS_TYPE_DICT_ENTRY, s);
++                                if (r < 0)
++                                        return bus_log_create_error(r);
++
++                                r = sd_bus_message_append_cmdline(m, s, &p);
++                                if (r < 0)
++                                        return r;
++                        }
++
++                        signature += k;
++
++                        r = sd_bus_message_close_container(m);
++                        break;
++                }
++
++                case SD_BUS_TYPE_UNIX_FD:
++                        log_error("UNIX file descriptor not supported as type.");
++                        return -EINVAL;
++
++                default:
++                        log_error("Unknown signature type %c.", t);
++                        return -EINVAL;
++                }
++
++                if (r < 0)
++                        return bus_log_create_error(r);
++        }
++
++        *x = p;
++        return 0;
++}
+diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
+index 2a2ef0e..a6a21a4 100644
+--- a/src/systemd/sd-bus.h
++++ b/src/systemd/sd-bus.h
+@@ -233,6 +233,7 @@ int sd_bus_message_get_priority(sd_bus_message *m, int64_t *priority);
+ int sd_bus_message_get_expect_reply(sd_bus_message *m);
+ int sd_bus_message_get_auto_start(sd_bus_message *m);
+ int sd_bus_message_get_allow_interactive_authorization(sd_bus_message *m);
++int sd_bus_message_append_cmdline(sd_bus_message *m, const char *signature, char ***x);
+ 
+ const char *sd_bus_message_get_signature(sd_bus_message *m, int complete);
+ const char *sd_bus_message_get_path(sd_bus_message *m);
+-- 
+1.8.3.1
+
diff --git a/meta-phosphor/common/recipes-core/systemd/systemd_%.bbappend b/meta-phosphor/common/recipes-core/systemd/systemd_%.bbappend
index 3c3dbac..0fd2931 100644
--- a/meta-phosphor/common/recipes-core/systemd/systemd_%.bbappend
+++ b/meta-phosphor/common/recipes-core/systemd/systemd_%.bbappend
@@ -3,6 +3,7 @@
 FILESEXTRAPATHS_append := "${THISDIR}/${PN}:"
 SRC_URI += "file://default.network"
 SRC_URI += "file://obmc-standby.target"
+SRC_URI += "file://0001-Export-message_append_cmdline.patch"
 
 FILES_${PN} += "${libdir}/systemd/network/default.network"
 FILES_${PN} += "${systemd_system_unitdir}/obmc-standby.target"