[systemd-commits] 3 commits - src/libsystemd-bus
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Nov 7 18:47:10 CET 2013
src/libsystemd-bus/bus-message.c | 69 ++++++++++++++++------------------
src/libsystemd-bus/test-bus-marshal.c | 7 +++
2 files changed, 41 insertions(+), 35 deletions(-)
New commits:
commit 405cd3aa0b80706331bb0255b95e3265ba8c264e
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 7 18:46:22 2013 +0100
bus: bus_message_read_strv_extend() should return 1 on success
Like all other message read calls bus_message_read_strv_extend() needs
to return 1 on sucess, and 0 on end of array.
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index abc1ae4..b6972ac 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -4435,7 +4435,7 @@ int bus_message_read_strv_extend(sd_bus_message *m, char ***l) {
if (r < 0)
return r;
- return 0;
+ return 1;
}
_public_ int sd_bus_message_read_strv(sd_bus_message *m, char ***l) {
commit 2efa7e1b2514ee6a84d9b5bae84bd16f78461409
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 7 18:40:14 2013 +0100
bus: fix output of bus_message_dump()
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 428568d..abc1ae4 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -4238,7 +4238,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
return r;
}
- fprintf(f, "BEGIN_MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
+ fprintf(f, "MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
for(;;) {
_cleanup_free_ char *prefix = NULL;
@@ -4262,6 +4262,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
log_error("Failed to peek type: %s", strerror(-r));
return r;
}
+
if (r == 0) {
if (level <= 1)
break;
@@ -4278,15 +4279,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
if (!prefix)
return log_oom();
- if (type == SD_BUS_TYPE_ARRAY)
- fprintf(f, "%s} END_ARRAY \n", prefix);
- else if (type == SD_BUS_TYPE_VARIANT)
- fprintf(f, "%s} END_VARIANT\n", prefix);
- else if (type == SD_BUS_TYPE_STRUCT)
- fprintf(f, "%s} END_STRUCT\n", prefix);
- else if (type == SD_BUS_TYPE_DICT_ENTRY)
- fprintf(f, "%s} END_DICT_ENTRY\n", prefix);
-
+ fprintf(f, "%s};\n", prefix);
continue;
}
@@ -4302,13 +4295,13 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
}
if (type == SD_BUS_TYPE_ARRAY)
- fprintf(f, "%sBEGIN_ARRAY \"%s\" {\n", prefix, contents);
+ fprintf(f, "%sARRAY \"%s\" {\n", prefix, contents);
else if (type == SD_BUS_TYPE_VARIANT)
- fprintf(f, "%sBEGIN_VARIANT \"%s\" {\n", prefix, contents);
+ fprintf(f, "%sVARIANT \"%s\" {\n", prefix, contents);
else if (type == SD_BUS_TYPE_STRUCT)
- fprintf(f, "%sBEGIN_STRUCT \"%s\" {\n", prefix, contents);
+ fprintf(f, "%sSTRUCT \"%s\" {\n", prefix, contents);
else if (type == SD_BUS_TYPE_DICT_ENTRY)
- fprintf(f, "%sBEGIN_DICT_ENTRY \"%s\" {\n", prefix, contents);
+ fprintf(f, "%sDICT_ENTRY \"%s\" {\n", prefix, contents);
level ++;
@@ -4326,55 +4319,55 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
switch (type) {
case SD_BUS_TYPE_BYTE:
- fprintf(f, "%sBYTE: %u\n", prefix, basic.u8);
+ fprintf(f, "%sBYTE %u;\n", prefix, basic.u8);
break;
case SD_BUS_TYPE_BOOLEAN:
- fprintf(f, "%sBOOLEAN: %s\n", prefix, yes_no(basic.i));
+ fprintf(f, "%sBOOLEAN %s;\n", prefix, yes_no(basic.i));
break;
case SD_BUS_TYPE_INT16:
- fprintf(f, "%sINT16: %i\n", prefix, basic.s16);
+ fprintf(f, "%sINT16 %i;\n", prefix, basic.s16);
break;
case SD_BUS_TYPE_UINT16:
- fprintf(f, "%sUINT16: %u\n", prefix, basic.u16);
+ fprintf(f, "%sUINT16 %u;\n", prefix, basic.u16);
break;
case SD_BUS_TYPE_INT32:
- fprintf(f, "%sINT32: %i\n", prefix, basic.s32);
+ fprintf(f, "%sINT32 %i;\n", prefix, basic.s32);
break;
case SD_BUS_TYPE_UINT32:
- fprintf(f, "%sUINT32: %u\n", prefix, basic.u32);
+ fprintf(f, "%sUINT32 %u;\n", prefix, basic.u32);
break;
case SD_BUS_TYPE_INT64:
- fprintf(f, "%sINT64: %lli\n", prefix, (long long) basic.s64);
+ fprintf(f, "%sINT64 %lli;\n", prefix, (long long) basic.s64);
break;
case SD_BUS_TYPE_UINT64:
- fprintf(f, "%sUINT64: %llu\n", prefix, (unsigned long long) basic.u64);
+ fprintf(f, "%sUINT64 %llu;\n", prefix, (unsigned long long) basic.u64);
break;
case SD_BUS_TYPE_DOUBLE:
- fprintf(f, "%sDOUBLE: %g\n", prefix, basic.d64);
+ fprintf(f, "%sDOUBLE %g;\n", prefix, basic.d64);
break;
case SD_BUS_TYPE_STRING:
- fprintf(f, "%sSTRING: \"%s\"\n", prefix, basic.string);
+ fprintf(f, "%sSTRING \"%s\";\n", prefix, basic.string);
break;
case SD_BUS_TYPE_OBJECT_PATH:
- fprintf(f, "%sOBJECT_PATH: \"%s\"\n", prefix, basic.string);
+ fprintf(f, "%sOBJECT_PATH \"%s\";\n", prefix, basic.string);
break;
case SD_BUS_TYPE_SIGNATURE:
- fprintf(f, "%sSIGNATURE: \"%s\"\n", prefix, basic.string);
+ fprintf(f, "%sSIGNATURE \"%s\";\n", prefix, basic.string);
break;
case SD_BUS_TYPE_UNIX_FD:
- fprintf(f, "%sUNIX_FD: %i\n", prefix, basic.i);
+ fprintf(f, "%sUNIX_FD %i;\n", prefix, basic.i);
break;
default:
@@ -4382,7 +4375,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
}
}
- fprintf(f, "} END_MESSAGE\n");
+ fprintf(f, "};\n");
return 0;
}
commit 5e86fd7b982e2d87537d4386bd1c9684c1ee7c43
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Nov 7 18:40:06 2013 +0100
bus: allow reading empty arrays with sd_bus_message_read_array()
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 3f9baca..428568d 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -3585,12 +3585,18 @@ _public_ int sd_bus_message_read_array(sd_bus_message *m,
c = message_get_container(m);
sz = BUS_MESSAGE_BSWAP32(m, *c->array_size);
- r = message_peek_body(m, &m->rindex, align, sz, &p);
- if (r < 0)
- goto fail;
- if (r == 0) {
- r = -EBADMSG;
- goto fail;
+ if (sz == 0)
+ /* Zero length array, let's return some aligned
+ * pointer that is not NULL */
+ p = (uint8_t*) NULL + align;
+ else {
+ r = message_peek_body(m, &m->rindex, align, sz, &p);
+ if (r < 0)
+ goto fail;
+ if (r == 0) {
+ r = -EBADMSG;
+ goto fail;
+ }
}
r = sd_bus_message_exit_container(m);
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 5e29a7b..8f36a71 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -92,6 +92,9 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_append_array(m, 'i', integer_array, sizeof(integer_array));
assert_se(r >= 0);
+ r = sd_bus_message_append_array(m, 'u', NULL, 0);
+ assert_se(r >= 0);
+
r = bus_message_seal(m, 4711);
assert_se(r >= 0);
@@ -210,6 +213,10 @@ int main(int argc, char *argv[]) {
assert_se(sz == sizeof(integer_array));
assert_se(memcmp(integer_array, return_array, sz) == 0);
+ r = sd_bus_message_read_array(m, 'u', (const void**) &return_array, &sz);
+ assert_se(r > 0);
+ assert_se(sz == 0);
+
r = sd_bus_message_peek_type(m, NULL, NULL);
assert_se(r == 0);
More information about the systemd-commits
mailing list