1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

sd-bus: Add sd_bus_reply()

While sd-bus already provides sd_bus_call() for calling a method
from a complete bus message object, We don't have an equivalent
function for replying from a method with a complete bus message
object.

Currently, we use sd_bus_send(call->bus, m, NULL) instead. Let's
add a shorthand for this pattern and name it sd_bus_reply().
This commit is contained in:
Daan De Meyer 2021-01-23 15:16:57 +00:00 committed by Yu Watanabe
parent 237ecfee15
commit eb83eb63b8
7 changed files with 39 additions and 5 deletions

View File

@ -11,7 +11,6 @@ manpages = [
['coredump.conf', '5', ['coredump.conf.d'], 'ENABLE_COREDUMP'],
['coredumpctl', '1', [], 'ENABLE_COREDUMP'],
['crypttab', '5', [], 'HAVE_LIBCRYPTSETUP'],
['veritytab', '5', [], 'HAVE_LIBCRYPTSETUP'],
['daemon', '7', [], ''],
['dnssec-trust-anchors.d',
'5',
@ -405,7 +404,10 @@ manpages = [
'sd_bus_reply_method_errorf',
'sd_bus_reply_method_errorfv'],
''],
['sd_bus_reply_method_return', '3', ['sd_bus_reply_method_returnv'], ''],
['sd_bus_reply_method_return',
'3',
['sd_bus_reply', 'sd_bus_reply_method_returnv'],
''],
['sd_bus_request_name',
'3',
['sd_bus_release_name',
@ -1128,6 +1130,7 @@ manpages = [
['systemd-user-runtime-dir', 'user-runtime-dir@.service'],
''],
['userdbctl', '1', [], 'ENABLE_USERDB'],
['vconsole.conf', '5', [], 'ENABLE_VCONSOLE']
['vconsole.conf', '5', [], 'ENABLE_VCONSOLE'],
['veritytab', '5', [], 'HAVE_LIBCRYPTSETUP']
]
# Really, do not edit.

View File

@ -144,6 +144,7 @@
<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_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>,

View File

@ -19,6 +19,7 @@
<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>
@ -40,6 +41,12 @@
<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>
@ -52,6 +59,11 @@
<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_new_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
<citerefentry><refentrytitle>sd_bus_new_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>
and sends it as a reply to the <parameter>call</parameter> message.</para>
</refsect1>
<refsect1>
@ -76,6 +88,8 @@
</para>
<para>Message <parameter>call</parameter> is not attached to a bus.</para>
<para>Message <parameter>m</parameter> is not a method reply message.</para>
</listitem>
</varlistentry>

View File

@ -740,6 +740,7 @@ global:
LIBSYSTEMD_248 {
global:
sd_bus_open_user_machine;
sd_bus_reply;
sd_event_source_set_ratelimit;
sd_event_source_get_ratelimit;

View File

@ -198,7 +198,7 @@ _public_ int sd_bus_reply_method_returnv(
return r;
}
return sd_bus_send(call->bus, m, NULL);
return sd_bus_reply(call, m);
}
_public_ int sd_bus_reply_method_return(
@ -239,7 +239,7 @@ _public_ int sd_bus_reply_method_error(
if (r < 0)
return r;
return sd_bus_send(call->bus, m, NULL);
return sd_bus_reply(call, m);
}
_public_ int sd_bus_reply_method_errorfv(

View File

@ -2604,6 +2604,20 @@ _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;

View File

@ -201,6 +201,7 @@ 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);