diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-05 14:55:28 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-05 14:56:48 +0200 |
commit | b7f247e0befb6595049bc2410fe370e21d1f7444 (patch) | |
tree | 065da2dca8c05ba22e324da1747fe4648aeccb3b /src | |
parent | d4100e2444fc78156a205bbb05703b31063e1248 (diff) |
bus: various improvements for test-bus-chat
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 7 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-chat.c | 36 |
2 files changed, 17 insertions, 26 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 8b8ce3c03e..6f8d444a66 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -1314,7 +1314,12 @@ int sd_bus_send_with_reply_and_block( /* Found a match! */ if (incoming->header->type == SD_BUS_MESSAGE_TYPE_METHOD_RETURN) { - *reply = incoming; + + if (reply) + *reply = incoming; + else + sd_bus_message_unref(incoming); + return 0; } diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c index 868a5b1408..533d78cc3b 100644 --- a/src/libsystemd-bus/test-bus-chat.c +++ b/src/libsystemd-bus/test-bus-chat.c @@ -206,14 +206,14 @@ static int server(sd_bus *bus) { client2_gone = true; } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "Slow")) { + sleep(1); + r = sd_bus_reply_method_return(bus, m, NULL); if (r < 0) { log_error("Failed to send reply: %s", strerror(-r)); goto fail; } - sleep(1); - } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "FileDescriptor")) { int fd; static const char x = 'X'; @@ -305,31 +305,18 @@ static void* client1(void*p) { goto finish; } - sd_bus_message_unref(m); - m = NULL; - r = sd_bus_message_new_method_call( + r = sd_bus_call_method( bus, "org.freedesktop.systemd.test", "/", "org.freedesktop.systemd.test", "FileDescriptor", - &m); - if (r < 0) { - log_error("Failed to allocate method call: %s", strerror(-r)); - goto finish; - } - - r = sd_bus_message_append(m, "h", pp[1]); - if (r < 0) { - log_error("Failed to append string: %s", strerror(-r)); - goto finish; - } - - sd_bus_message_unref(reply); - reply = NULL; - r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, &reply); + &error, + NULL, + "h", + pp[1]); if (r < 0) { - log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); + log_error("Failed to issue method call: %s", strerror(-r)); goto finish; } @@ -352,12 +339,11 @@ finish: "org.freedesktop.systemd.test", "ExitClient1", &q); - if (r < 0) { + if (r < 0) log_error("Failed to allocate method call: %s", strerror(-r)); - goto finish; - } + else + sd_bus_send(bus, q, NULL); - sd_bus_send(bus, q, NULL); sd_bus_flush(bus); sd_bus_unref(bus); } |