diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-29 18:58:30 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-29 18:58:30 +0200 |
commit | 9030ca462bd13cd6536299814e4a71d5c5e85be9 (patch) | |
tree | 43716aa3042f274b4578799725cfb03c5682e9d8 /src/libsystemd/sd-bus | |
parent | 47ee3ee03483efd271642d5043070cbd171f19d4 (diff) |
sd-bus: allow passing NULL as bus parameter to sd_bus_send()
If NULL is specified for the bus it is now automatically derived from
the passed in message.
This commit also changes a number of invocations of sd_bus_send() to
make use of this.
Diffstat (limited to 'src/libsystemd/sd-bus')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 41fbe7d4af..214b3d04df 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1695,8 +1695,11 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, _cleanup_bus_message_unref_ sd_bus_message *m = sd_bus_message_ref(_m); int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); @@ -1781,8 +1784,11 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie) { _public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *cookie) { int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); if (!BUS_IS_OPEN(bus->state)) @@ -1838,11 +1844,14 @@ _public_ int sd_bus_call_async( _cleanup_bus_slot_unref_ sd_bus_slot *s = NULL; int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL); assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); assert_return(callback, -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); @@ -1936,11 +1945,14 @@ _public_ int sd_bus_call( unsigned i; int r; - assert_return(bus, -EINVAL); assert_return(m, -EINVAL); assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL); assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); assert_return(!bus_error_is_dirty(error), -EINVAL); + + if (!bus) + bus = m->bus; + assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); |