From: Zbigniew Jędrzejewski-Szmek Date: Thu, 8 Apr 2021 12:59:10 +0000 (+0200) Subject: sd-bus: make sd_bus_is_{ready,open} accept NULL X-Git-Tag: v249-rc1~457^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bbb76f62123f59ad871bebd00fdcd3f0c974275;p=thirdparty%2Fsystemd.git sd-bus: make sd_bus_is_{ready,open} accept NULL We didn't document this behaviour one way or another, so I think it's OK to change. All callers do the NULL check before callling this to avoid the assert warning, so it seems reasonable to do it internally. sd_bus_can_send() is similar, but there we expressly say that an error is returned on NULL, so I didn't change it. --- diff --git a/man/sd_bus_is_open.xml b/man/sd_bus_is_open.xml index 8e0aed29b33..621ed272bb8 100644 --- a/man/sd_bus_is_open.xml +++ b/man/sd_bus_is_open.xml @@ -57,6 +57,9 @@ zero outside of this state, and positive otherwise. Effectively, this function returns positive while regular messages can be sent or received on the connection. + The bus argument may be NULL, zero is also returned in + that case. + To be notified when the connection is fully established, use sd_bus_set_connected_signal3 and install a match for the Connected() signal on the @@ -68,8 +71,8 @@ Return Value - On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style - error code. + Those functions return 0 if the bus is not in the given state, and a positive + integer when it is. On failure, a negative errno-style error code is returned. Errors diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index e719c74370f..2f4e67c97ef 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1800,7 +1800,9 @@ void bus_enter_closing(sd_bus *bus) { DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_bus, sd_bus, bus_free); _public_ int sd_bus_is_open(sd_bus *bus) { - assert_return(bus, -EINVAL); + if (!bus) + return 0; + assert_return(bus = bus_resolve(bus), -ENOPKG); assert_return(!bus_pid_changed(bus), -ECHILD); @@ -1808,7 +1810,9 @@ _public_ int sd_bus_is_open(sd_bus *bus) { } _public_ int sd_bus_is_ready(sd_bus *bus) { - assert_return(bus, -EINVAL); + if (!bus) + return 0; + assert_return(bus = bus_resolve(bus), -ENOPKG); assert_return(!bus_pid_changed(bus), -ECHILD);