summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-19 00:20:10 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-20 05:44:02 +0100
commit6c41cf445912c12e14b1e94414a0fce1fa060ac2 (patch)
tree59411b2c84b2b8ee2036f94e3538c07d2f8f453d
parentsysctl.d: silence warning if net.core.default_qdisc cannot be set (diff)
downloadsystemd-6c41cf445912c12e14b1e94414a0fce1fa060ac2.tar.xz
systemd-6c41cf445912c12e14b1e94414a0fce1fa060ac2.zip
sd-bus: simplify sd_bus_reply()
there's no point in having two arguments, if one does as well.
-rw-r--r--NEWS5
-rw-r--r--man/rules/meson.build7
-rw-r--r--man/sd-bus.xml14
-rw-r--r--man/sd_bus_reply_method_return.xml13
-rw-r--r--man/sd_bus_send.xml10
-rw-r--r--src/libsystemd/libsystemd.sym2
-rw-r--r--src/libsystemd/sd-bus/bus-convenience.c12
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c14
-rw-r--r--src/systemd/sd-bus.h2
9 files changed, 34 insertions, 45 deletions
diff --git a/NEWS b/NEWS
index fb0c096462..3ee2381191 100644
--- a/NEWS
+++ b/NEWS
@@ -123,8 +123,9 @@ CHANGES WITH 248:
systemctl --user -M lennart@ start quux
- * sd-bus also gained a convenience function sd_bus_reply() to call
- sd_bus_send() with an existing reply message.
+ * sd-bus also gained a convenience function sd_bus_message_send() to
+ simplify invocations of sd_bus_send(), taking only a single
+ parameter: the message to send.
* sd-event allows rate limits to be set on event sources, for dealing
with high-priority event sources that might starve out others. See
diff --git a/man/rules/meson.build b/man/rules/meson.build
index c8e589e0f0..763863afef 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -405,17 +405,14 @@ manpages = [
'sd_bus_reply_method_errorf',
'sd_bus_reply_method_errorfv'],
''],
- ['sd_bus_reply_method_return',
- '3',
- ['sd_bus_reply', 'sd_bus_reply_method_returnv'],
- ''],
+ ['sd_bus_reply_method_return', '3', ['sd_bus_reply_method_returnv'], ''],
['sd_bus_request_name',
'3',
['sd_bus_release_name',
'sd_bus_release_name_async',
'sd_bus_request_name_async'],
''],
- ['sd_bus_send', '3', ['sd_bus_send_to'], ''],
+ ['sd_bus_send', '3', ['sd_bus_message_send', 'sd_bus_send_to'], ''],
['sd_bus_set_address', '3', ['sd_bus_get_address', 'sd_bus_set_exec'], ''],
['sd_bus_set_close_on_exit', '3', ['sd_bus_get_close_on_exit'], ''],
['sd_bus_set_connected_signal', '3', ['sd_bus_get_connected_signal'], ''],
diff --git a/man/sd-bus.xml b/man/sd-bus.xml
index bfe07e88ca..9224f28129 100644
--- a/man/sd-bus.xml
+++ b/man/sd-bus.xml
@@ -54,9 +54,9 @@
<citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_call_method_async</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_can_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_get_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_emit_interfaces_added</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_emit_interfaces_added_strv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
@@ -83,19 +83,19 @@
<citerefentry><refentrytitle>sd_bus_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_n_queued_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_get_name_machine_id</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_get_name_machine_id</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_property</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_get_property_trivial</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_property_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_property_strv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_get_property_trivial</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_scope</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_tid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_unique_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_interface_name_is_valid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_is_monitor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_is_monitor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_server</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_list_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
@@ -128,12 +128,13 @@
<citerefentry><refentrytitle>sd_bus_message_read_array</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_read_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_read_strv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_message_reply</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_rewind</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_seal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_set_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_set_destination</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_message_set_sender</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_set_expect_reply</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_message_set_sender</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_verify_type</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_negotiate_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
@@ -142,9 +143,8 @@
<citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_query_sender_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_query_sender_privilege</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_reply_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_reply_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-<citerefentry><refentrytitle>sd_bus_reply</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>sd_bus_reply_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_request_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_send_to</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
diff --git a/man/sd_bus_reply_method_return.xml b/man/sd_bus_reply_method_return.xml
index cf1e422a38..b9003e8293 100644
--- a/man/sd_bus_reply_method_return.xml
+++ b/man/sd_bus_reply_method_return.xml
@@ -19,7 +19,6 @@
<refnamediv>
<refname>sd_bus_reply_method_return</refname>
<refname>sd_bus_reply_method_returnv</refname>
- <refname>sd_bus_reply</refname>
<refpurpose>Reply to a D-Bus method call</refpurpose>
</refnamediv>
@@ -41,12 +40,6 @@
<paramdef>const char *<parameter>types</parameter></paramdef>
<paramdef>va_list <parameter>ap</parameter></paramdef>
</funcprototype>
-
- <funcprototype>
- <funcdef>int sd_bus_reply</funcdef>
- <paramdef>const sd_bus_message *<parameter>call</parameter></paramdef>
- <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
- </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
@@ -59,12 +52,6 @@
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
If no reply is expected to <parameter>call</parameter>, this function succeeds without sending a
reply.</para>
-
- <para><function>sd_bus_reply()</function> takes a complete bus message object created with either
- <citerefentry><refentrytitle>sd_bus_message_new_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>
- or
- <citerefentry><refentrytitle>sd_bus_message_new_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>
- and sends it as a reply to the <parameter>call</parameter> message.</para>
</refsect1>
<refsect1>
diff --git a/man/sd_bus_send.xml b/man/sd_bus_send.xml
index c4c623a1e8..02ba3b8104 100644
--- a/man/sd_bus_send.xml
+++ b/man/sd_bus_send.xml
@@ -19,6 +19,7 @@
<refnamediv>
<refname>sd_bus_send</refname>
<refname>sd_bus_send_to</refname>
+ <refname>sd_bus_message_send</refname>
<refpurpose>Queue a D-Bus message for transfer</refpurpose>
</refnamediv>
@@ -41,6 +42,11 @@
<paramdef>const char *<parameter>destination</parameter></paramdef>
<paramdef>uint64_t *<parameter>cookie</parameter></paramdef>
</funcprototype>
+
+ <funcprototype>
+ <funcdef>int sd_bus_message_send</funcdef>
+ <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
@@ -76,6 +82,10 @@
call fails.
<citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry> should
be invoked to write out any queued message data to the transport.</para>
+
+ <para><function>sd_bus_message_send()</function> is the same as <function>sd_bus_send()</function> but
+ without the first and last argument. It's equivalent to
+ <function>sd_bus_message_send(sd_bus_message_get_bus(m), m, NULL)</function>.</para>
</refsect1>
<refsect1>
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index fbe9803d42..78454acbc0 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -740,7 +740,7 @@ global:
LIBSYSTEMD_248 {
global:
sd_bus_open_user_machine;
- sd_bus_reply;
+ sd_bus_message_send;
sd_event_source_set_ratelimit;
sd_event_source_get_ratelimit;
diff --git a/src/libsystemd/sd-bus/bus-convenience.c b/src/libsystemd/sd-bus/bus-convenience.c
index 08f61ecc15..a36aeb238e 100644
--- a/src/libsystemd/sd-bus/bus-convenience.c
+++ b/src/libsystemd/sd-bus/bus-convenience.c
@@ -9,6 +9,14 @@
#include "bus-type.h"
#include "string-util.h"
+_public_ int sd_bus_message_send(sd_bus_message *reply) {
+ assert_return(reply, -EINVAL);
+ assert_return(reply->bus, -EINVAL);
+ assert_return(!bus_pid_changed(reply->bus), -ECHILD);
+
+ return sd_bus_send(reply->bus, reply, NULL);
+}
+
_public_ int sd_bus_emit_signalv(
sd_bus *bus,
const char *path,
@@ -198,7 +206,7 @@ _public_ int sd_bus_reply_method_returnv(
return r;
}
- return sd_bus_reply(call, m);
+ return sd_bus_message_send(m);
}
_public_ int sd_bus_reply_method_return(
@@ -239,7 +247,7 @@ _public_ int sd_bus_reply_method_error(
if (r < 0)
return r;
- return sd_bus_reply(call, m);
+ return sd_bus_message_send(m);
}
_public_ int sd_bus_reply_method_errorfv(
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 1f7e71c66e..6b1f25cc02 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -2604,20 +2604,6 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
}
}
-int sd_bus_reply(const sd_bus_message *call, sd_bus_message *reply) {
- assert_return(call, -EINVAL);
- assert_return(call->sealed, -EPERM);
- assert_return(call->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL);
- assert_return(call->bus, -EINVAL);
- assert_return(!bus_pid_changed(call->bus), -ECHILD);
- assert_return(reply, -EINVAL);
- assert_return(
- IN_SET(reply->header->type, SD_BUS_MESSAGE_METHOD_RETURN, SD_BUS_MESSAGE_METHOD_ERROR),
- -EINVAL);
-
- return sd_bus_send(call->bus, reply, NULL);
-}
-
static int process_timeout(sd_bus *bus) {
_cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message* m = NULL;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 1829861397..a07a76170c 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -201,7 +201,6 @@ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie);
int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *cookie);
int sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *ret_error, sd_bus_message **reply);
int sd_bus_call_async(sd_bus *bus, sd_bus_slot **slot, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec);
-int sd_bus_reply(const sd_bus_message *call, sd_bus_message *reply);
int sd_bus_get_fd(sd_bus *bus);
int sd_bus_get_events(sd_bus *bus);
@@ -355,6 +354,7 @@ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *machin
/* Convenience calls */
+int sd_bus_message_send(sd_bus_message *m);
int sd_bus_call_methodv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, va_list ap);
int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, ...);
int sd_bus_call_method_asyncv(sd_bus *bus, sd_bus_slot **slot, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, va_list ap);