diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-03-19 21:41:21 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-19 21:41:21 +0100 |
commit | a3d59cd1b0a2738d06893948492113f2c35be0af (patch) | |
tree | a5a94ef91ca81f73c5a327f37cc0aeabdb491068 /src/libsystemd/sd-bus/sd-bus.c | |
parent | 598459cebac7cc93089769a992e7b03287f77e12 (diff) |
sd-bus: don't use assert_return() to check for disconnected bus connections
A terminated connection is a runtime error and not a developer mistake,
hence don't use assert_return() to check for it.
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index fa6d43adc8..15c767723c 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1638,11 +1638,13 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, int r; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(m, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; + if (m->n_fds > 0) { r = sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD); if (r < 0) @@ -1718,10 +1720,12 @@ _public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destinat int r; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(m, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; + if (!streq_ptr(m->destination, destination)) { if (!destination) @@ -1773,7 +1777,6 @@ _public_ int sd_bus_call_async( int r; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); 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); @@ -1781,6 +1784,9 @@ _public_ int sd_bus_call_async( assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; + r = hashmap_ensure_allocated(&bus->reply_callbacks, uint64_hash_func, uint64_compare_func); if (r < 0) return r; @@ -1887,7 +1893,6 @@ _public_ int sd_bus_call( int r; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); 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); @@ -1895,6 +1900,9 @@ _public_ int sd_bus_call( assert_return(!bus_pid_changed(bus), -ECHILD); assert_return(!bus->is_kernel || !(bus->hello_flags & KDBUS_HELLO_MONITOR), -EROFS); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; + r = bus_ensure_running(bus); if (r < 0) return r; @@ -2025,9 +2033,11 @@ _public_ int sd_bus_get_events(sd_bus *bus) { int flags = 0; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state) || bus->state == BUS_CLOSING, -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); + if (!BUS_IS_OPEN(bus->state) && bus->state != BUS_CLOSING) + return -ENOTCONN; + if (bus->state == BUS_OPENING) flags |= POLLOUT; else if (bus->state == BUS_AUTHENTICATING) { @@ -2052,9 +2062,11 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) { assert_return(bus, -EINVAL); assert_return(timeout_usec, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state) || bus->state == BUS_CLOSING, -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); + if (!BUS_IS_OPEN(bus->state) && bus->state != BUS_CLOSING) + return -ENOTCONN; + if (bus->track_queue) { *timeout_usec = 0; return 1; @@ -2642,7 +2654,8 @@ static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) { if (bus->state == BUS_CLOSING) return 1; - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; e = sd_bus_get_events(bus); if (e < 0) @@ -2697,7 +2710,8 @@ _public_ int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec) { if (bus->state == BUS_CLOSING) return 0; - assert_return(BUS_IS_OPEN(bus->state) , -ENOTCONN); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; if (bus->rqueue_size > 0) return 0; @@ -2714,7 +2728,8 @@ _public_ int sd_bus_flush(sd_bus *bus) { if (bus->state == BUS_CLOSING) return 0; - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; r = bus_ensure_running(bus); if (r < 0) @@ -3224,9 +3239,13 @@ _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **re assert_return(bus, -EINVAL); assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP); assert_return(ret, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); - assert_return(!bus->is_kernel, -ENOTSUP); + + if (!bus->is_kernel) + return -ENOTSUP; + + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; if (!bus->ucred_valid && !isempty(bus->label)) return -ENODATA; @@ -3265,9 +3284,13 @@ _public_ int sd_bus_try_close(sd_bus *bus) { int r; assert_return(bus, -EINVAL); - assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); - assert_return(bus->is_kernel, -ENOTSUP); + + if (!bus->is_kernel) + return -ENOTSUP; + + if (!BUS_IS_OPEN(bus->state)) + return -ENOTCONN; if (bus->rqueue_size > 0) return -EBUSY; |