diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-22 01:49:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-22 01:49:56 +0100 |
commit | d728d708c3ccfcb34f6d7673f7855fbf0c10aeec (patch) | |
tree | d6d059970324202b65a5077da38a566f356c403d /src/libsystemd-bus/sd-bus.c | |
parent | 9f26c90cb50c45d4549c4dd569917b4ac143b94d (diff) |
bus: rework synchronization logic
Instead of allowing certain actions fail during authentication and
connection setup, implicitly synchronize on the connection to be set up
completely before returning.
Diffstat (limited to 'src/libsystemd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 049bd356a0..6a6d43fac0 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -35,6 +35,7 @@ #include "bus-message.h" #include "bus-type.h" +static int ensure_running(sd_bus *bus); static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec); static void bus_free(sd_bus *b) { @@ -778,27 +779,37 @@ int sd_bus_is_open(sd_bus *bus) { return bus->fd >= 0; } -int sd_bus_is_running(sd_bus *bus) { +int sd_bus_can_send(sd_bus *bus, char type) { + int r; + if (!bus) return -EINVAL; - if (bus->fd < 0) - return -ENOTCONN; + if (type == SD_BUS_TYPE_UNIX_FD) { + r = ensure_running(bus); + if (r < 0) + return r; - return bus->state == BUS_RUNNING; + return bus->can_fds; + } + + return bus_type_is_valid(type); } -int sd_bus_can_send(sd_bus *bus, char type) { +int sd_bus_get_peer(sd_bus *bus, sd_id128_t *peer) { + int r; if (!bus) return -EINVAL; - if (bus->state != BUS_RUNNING && bus->state != BUS_HELLO) - return -EAGAIN; + if (!peer) + return -EINVAL; - if (type == SD_BUS_TYPE_UNIX_FD) - return bus->can_fds; + r = ensure_running(bus); + if (r < 0) + return r; - return bus_type_is_valid(type); + *peer = bus->peer; + return 0; } static int bus_seal_message(sd_bus *b, sd_bus_message *m) { @@ -1243,22 +1254,15 @@ static int ensure_running(sd_bus *bus) { assert(bus); - r = sd_bus_is_running(bus); - if (r != 0) - return r; + if (bus->state == BUS_RUNNING) + return 1; for (;;) { - int k; - r = sd_bus_process(bus, NULL); - if (r < 0) return r; - - k = sd_bus_is_running(bus); - if (k != 0) - return k; - + if (bus->state == BUS_RUNNING) + return 1; if (r > 0) continue; |