diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-07-13 17:38:47 +0900 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-07-16 15:11:50 +0200 |
commit | 385b2eb262a99373f09d01b7f5571dd71a14dc98 (patch) | |
tree | d36b582c1f3959330202689b4a18d183ccd70975 /src/libsystemd/sd-bus/sd-bus.c | |
parent | db9eee7e4535eea888afbefc49da75cceb79aa10 (diff) | |
download | systemd-385b2eb262a99373f09d01b7f5571dd71a14dc98.tar.gz |
sd-bus: make BUS_DEFAULT_TIMEOUT configurable
This adds sd_bus_{get,set}_method_call_timeout().
If the timeout is not set or set to 0, then the timeout value is
parsed from $SYSTEMD_BUS_TIMEOUT= environment variable. If the
environment variable is not set, then built-in timeout is used.
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index ce49580edb..deb664540a 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1609,8 +1609,11 @@ static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) { return 0; } - if (timeout == 0) - timeout = BUS_DEFAULT_TIMEOUT; + if (timeout == 0) { + r = sd_bus_get_method_call_timeout(b, &timeout); + if (r < 0) + return r; + } if (!m->sender && b->patch_sender) { r = sd_bus_message_set_sender(m, b->patch_sender); @@ -4073,3 +4076,36 @@ _public_ int sd_bus_get_n_queued_write(sd_bus *bus, uint64_t *ret) { *ret = bus->wqueue_size; return 0; } + +_public_ int sd_bus_set_method_call_timeout(sd_bus *bus, uint64_t usec) { + assert_return(bus, -EINVAL); + assert_return(bus = bus_resolve(bus), -ENOPKG); + + bus->method_call_timeout = usec; + return 0; +} + +_public_ int sd_bus_get_method_call_timeout(sd_bus *bus, uint64_t *ret) { + const char *e; + usec_t usec; + + assert_return(bus, -EINVAL); + assert_return(bus = bus_resolve(bus), -ENOPKG); + assert_return(ret, -EINVAL); + + if (bus->method_call_timeout != 0) { + *ret = bus->method_call_timeout; + return 0; + } + + e = secure_getenv("SYSTEMD_BUS_TIMEOUT"); + if (e && parse_sec(e, &usec) >= 0 && usec != 0) { + /* Save the parsed value to avoid multiple parsing. To change the timeout value, + * use sd_bus_set_method_call_timeout() instead of setenv(). */ + *ret = bus->method_call_timeout = usec; + return 0; + } + + *ret = bus->method_call_timeout = BUS_DEFAULT_TIMEOUT; + return 0; +} |