]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_call.xml
Merge pull request #32963 from yuwata/test-64-btrfs
[thirdparty/systemd.git] / man / sd_bus_call.xml
CommitLineData
953ee402
DDM
1<?xml version='1.0'?>
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
953ee402
DDM
5
6<refentry id="sd_bus_call"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>sd_bus_call</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>sd_bus_call</refentrytitle>
16 <manvolnum>3</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>sd_bus_call</refname>
21 <refname>sd_bus_call_async</refname>
22
23 <refpurpose>Invoke a D-Bus method call</refpurpose>
24 </refnamediv>
25
26 <refsynopsisdiv>
27 <funcsynopsis>
28 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
29
af955f91
LP
30 <xi:include href="sd_bus_add_match.xml" xpointer="sd_bus_message_handler_t"/>
31
953ee402
DDM
32 <funcprototype>
33 <funcdef>int <function>sd_bus_call</function></funcdef>
34 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
35 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
36 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
37 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
38 <paramdef>sd_bus_message **<parameter>reply</parameter></paramdef>
39 </funcprototype>
40
41 <funcprototype>
42 <funcdef>int <function>sd_bus_call_async</function></funcdef>
43 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
44 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
45 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
46 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
47 <paramdef>void *<parameter>userdata</parameter></paramdef>
48 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
49 </funcprototype>
50 </funcsynopsis>
51 </refsynopsisdiv>
52
53 <refsect1>
54 <title>Description</title>
55
56 <para><function>sd_bus_call()</function> takes a complete bus message object and calls the
47203ed0 57 corresponding D-Bus method. On success, the response is stored in <parameter>reply</parameter>.
953ee402
DDM
58 <parameter>usec</parameter> indicates the timeout in microseconds. If
59 <parameter>ret_error</parameter> is not <constant>NULL</constant> and
47203ed0
DDM
60 <function>sd_bus_call()</function> fails (either because of an internal error or because it
61 received a D-Bus error reply), <parameter>ret_error</parameter> is initialized to an instance of
62 <structname>sd_bus_error</structname> describing the error.</para>
953ee402 63
2efa512a
LP
64 <para><function>sd_bus_call_async()</function> is like <function>sd_bus_call()</function> but works
65 asynchronously. The <parameter>callback</parameter> indicates the function to call when the response
66 arrives. The <parameter>userdata</parameter> pointer will be passed to the callback function, and may be
67 chosen freely by the caller. If <parameter>slot</parameter> is not <constant>NULL</constant> and
68 <function>sd_bus_call_async()</function> succeeds, <parameter>slot</parameter> is set to a slot object
69 which can be used to cancel the method call at a later time using
953ee402 70 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
2efa512a
LP
71 If <parameter>slot</parameter> is <constant>NULL</constant>, the lifetime of the method call is bound to
72 the lifetime of the bus object itself, and it cannot be cancelled independently. See
953ee402 73 <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>
47203ed0 74 for details. <parameter>callback</parameter> is called when a reply arrives with the reply,
2efa512a
LP
75 <parameter>userdata</parameter> and an <structname>sd_bus_error</structname> output parameter as its
76 arguments. Unlike <function>sd_bus_call()</function>, the <structname>sd_bus_error</structname> output
77 parameter passed to the callback will be empty. To determine whether the method call succeeded, use
953ee402 78 <citerefentry><refentrytitle>sd_bus_message_is_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>
47203ed0 79 on the reply message passed to the callback instead. If the callback returns zero and the
2efa512a
LP
80 <structname>sd_bus_error</structname> output parameter is still empty when the callback finishes, other
81 handlers registered with functions such as
47203ed0 82 <citerefentry><refentrytitle>sd_bus_add_filter</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
2efa512a
LP
83 <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> are
84 given a chance to process the message. If the callback returns a non-zero value or the
85 <structname>sd_bus_error</structname> output parameter is not empty when the callback finishes, no
86 further processing of the message is done. Generally, you want to return zero from the callback to give
87 other registered handlers a chance to process the reply as well. (Note that the
88 <structname>sd_bus_error</structname> parameter is an output parameter of the callback function, not an
89 input parameter; it can be used to propagate errors from the callback handler, it will not receive any
90 error that was received as method reply.)</para>
953ee402 91
e6ce785d 92 <para>The message <parameter>m</parameter> passed to the callback is only borrowed, that is, the callback should
93 not call <citerefentry><refentrytitle>sd_bus_message_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
94 on it. If the callback wants to hold on to the message beyond the lifetime of the callback, it needs to call
95 <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry> to create a
96 new reference.</para>
97
cc46b9d9
DDM
98 <para>If <parameter>usec</parameter> is zero, the default D-Bus method call timeout is used. See
99 <citerefentry><refentrytitle>sd_bus_get_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
953ee402
DDM
100 </para>
101
102 </refsect1>
103
104 <refsect1>
105 <title>Return Value</title>
106
107 <para>On success, these functions return a non-negative integer. On failure, they return a
108 negative errno-style error code.</para>
109
110 <refsect2 id='errors'>
111 <title>Errors</title>
112
141fdc8a
ZJS
113 <para>When <function>sd_bus_call()</function> internally receives a D-Bus error reply, it will set
114 <parameter>ret_error</parameter> if it is not <constant>NULL</constant>, and will return a negative
115 value mapped from the error reply, see
c660668e
YW
116 <citerefentry><refentrytitle>sd_bus_error_get_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
117 </para>
953ee402 118
953ee402
DDM
119 <para>Returned errors may indicate the following problems:</para>
120
121 <variablelist>
122 <varlistentry>
123 <term><constant>-EINVAL</constant></term>
124
08b96745
DT
125 <listitem>
126 <para>The input parameter <parameter>m</parameter> is <constant>NULL</constant>.
127 </para>
ec07c3c8 128
08b96745
DT
129 <para>The input parameter <parameter>m</parameter> is not a D-Bus method call.
130 To create a new D-Bus method call, use
131 <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
132 </para>
953ee402 133
08b96745
DT
134 <para>The input parameter <parameter>m</parameter> has the
135 <constant>BUS_MESSAGE_NO_REPLY_EXPECTED</constant> flag set.</para>
953ee402 136
08b96745
DT
137 <para>The input parameter <parameter>error</parameter> is
138 non-<constant>NULL</constant> but was not set to <constant>SD_BUS_ERROR_NULL</constant>.
139 </para>
08b96745 140 </listitem>
953ee402
DDM
141 </varlistentry>
142
143 <varlistentry>
144 <term><constant>-ECHILD</constant></term>
145
146 <listitem><para>The bus connection was allocated in a parent process and is being reused
87fe0a69 147 in a child process after <function>fork()</function>.</para></listitem>
953ee402
DDM
148 </varlistentry>
149
150 <varlistentry>
151 <term><constant>-ENOTCONN</constant></term>
152
b0f4c02e 153 <listitem><para>The input parameter <parameter>bus</parameter> is
87fe0a69 154 <constant>NULL</constant> or the bus is not connected.</para></listitem>
953ee402
DDM
155 </varlistentry>
156
157 <varlistentry>
158 <term><constant>-ECONNRESET</constant></term>
159
b0f4c02e 160 <listitem><para>The bus connection was closed while waiting for the response.
87fe0a69 161 </para></listitem>
953ee402
DDM
162 </varlistentry>
163
164 <varlistentry>
165 <term><constant>-ETIMEDOUT</constant></term>
166
87fe0a69 167 <listitem><para>A response was not received within the given timeout.</para></listitem>
953ee402
DDM
168 </varlistentry>
169
170 <varlistentry>
171 <term><constant>-ELOOP</constant></term>
172
173 <listitem><para>The message <parameter>m</parameter> is addressed to its own client.
87fe0a69 174 </para></listitem>
953ee402
DDM
175 </varlistentry>
176
177 <varlistentry>
178 <term><constant>-ENOMEM</constant></term>
179
87fe0a69 180 <listitem><para>Memory allocation failed.</para></listitem>
953ee402
DDM
181 </varlistentry>
182 </variablelist>
183 </refsect2>
184 </refsect1>
185
186 <xi:include href="libsystemd-pkgconfig.xml" />
187
69106f47
AK
188 <refsect1>
189 <title>History</title>
00f95506 190 <para><function>sd_bus_call()</function> and
87fe0a69 191 <function>sd_bus_call_async()</function> were added in version 221.</para>
69106f47
AK
192 </refsect1>
193
953ee402
DDM
194 <refsect1>
195 <title>See Also</title>
196
13a69c12
DT
197 <para><simplelist type="inline">
198 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
199 <member><citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
200 <member><citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
201 <member><citerefentry><refentrytitle>sd_bus_call_method_async</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
202 <member><citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
203 <member><citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
204 <member><citerefentry><refentrytitle>sd_bus_error</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
205 </simplelist></para>
953ee402
DDM
206 </refsect1>
207
208</refentry>