summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-convenience.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-bus/bus-convenience.c')
-rw-r--r--src/libsystemd/sd-bus/bus-convenience.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/libsystemd/sd-bus/bus-convenience.c b/src/libsystemd/sd-bus/bus-convenience.c
index 6e02ad365c..c5b9cd4caa 100644
--- a/src/libsystemd/sd-bus/bus-convenience.c
+++ b/src/libsystemd/sd-bus/bus-convenience.c
@@ -36,9 +36,11 @@ _public_ int sd_bus_emit_signal(
int r;
assert_return(bus, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_message_new_signal(bus, &m, path, interface, member);
if (r < 0)
return r;
@@ -70,9 +72,11 @@ _public_ int sd_bus_call_method(
int r;
assert_return(bus, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_message_new_method_call(bus, &m, destination, path, interface, member);
if (r < 0)
return r;
@@ -100,9 +104,12 @@ _public_ int sd_bus_reply_method_return(
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
@@ -134,9 +141,12 @@ _public_ int sd_bus_reply_method_error(
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
assert_return(sd_bus_error_is_set(e), -EINVAL);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
@@ -159,9 +169,12 @@ _public_ int sd_bus_reply_method_errorf(
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
@@ -182,9 +195,12 @@ _public_ int sd_bus_reply_method_errno(
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
@@ -208,9 +224,12 @@ _public_ int sd_bus_reply_method_errnof(
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
return 0;
@@ -239,9 +258,11 @@ _public_ int sd_bus_get_property(
assert_return(member_name_is_valid(member), -EINVAL);
assert_return(reply, -EINVAL);
assert_return(signature_is_single(type, false), -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &rep, "ss", strempty(interface), member);
if (r < 0)
return r;
@@ -273,9 +294,11 @@ _public_ int sd_bus_get_property_trivial(
assert_return(member_name_is_valid(member), -EINVAL);
assert_return(bus_type_is_trivial(type), -EINVAL);
assert_return(ptr, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
@@ -309,9 +332,11 @@ _public_ int sd_bus_get_property_string(
assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
assert_return(member_name_is_valid(member), -EINVAL);
assert_return(ret, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
@@ -348,9 +373,11 @@ _public_ int sd_bus_get_property_strv(
assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
assert_return(member_name_is_valid(member), -EINVAL);
assert_return(ret, -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &reply, "ss", strempty(interface), member);
if (r < 0)
return r;
@@ -383,9 +410,11 @@ _public_ int sd_bus_set_property(
assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
assert_return(member_name_is_valid(member), -EINVAL);
assert_return(signature_is_single(type, false), -EINVAL);
- assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
assert_return(!bus_pid_changed(bus), -ECHILD);
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
r = sd_bus_message_new_method_call(bus, &m, destination, path, "org.freedesktop.DBus.Properties", "Set");
if (r < 0)
return r;
@@ -416,9 +445,12 @@ _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_b
assert_return(call, -EINVAL);
assert_return(call->sealed, -EPERM);
- assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN);
+ assert_return(call->bus, -EINVAL);
assert_return(!bus_pid_changed(call->bus), -ECHILD);
+ if (!BUS_IS_OPEN(call->bus->state))
+ return -ENOTCONN;
+
c = sd_bus_message_get_creds(call);
/* All data we need? */