]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_default.xml
Correct more spelling errors.
[thirdparty/systemd.git] / man / sd_bus_default.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
cd6d5e1c 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
cd6d5e1c
ZJS
4
5<!--
572eb058 6 SPDX-License-Identifier: LGPL-2.1+
cd6d5e1c
ZJS
7-->
8
7d6b2723 9<refentry id="sd_bus_default" xmlns:xi="http://www.w3.org/2001/XInclude">
cd6d5e1c
ZJS
10
11 <refentryinfo>
4a2af8d7 12 <title>sd_bus_default</title>
cd6d5e1c 13 <productname>systemd</productname>
cd6d5e1c
ZJS
14 </refentryinfo>
15
16 <refmeta>
4a2af8d7 17 <refentrytitle>sd_bus_default</refentrytitle>
cd6d5e1c
ZJS
18 <manvolnum>3</manvolnum>
19 </refmeta>
20
21 <refnamediv>
4a2af8d7
LP
22 <refname>sd_bus_default</refname>
23 <refname>sd_bus_default_user</refname>
24 <refname>sd_bus_default_system</refname>
25
26 <refname>sd_bus_open</refname>
f00ded93 27 <refname>sd_bus_open_with_description</refname>
cd6d5e1c 28 <refname>sd_bus_open_user</refname>
f00ded93 29 <refname>sd_bus_open_user_with_description</refname>
cd6d5e1c 30 <refname>sd_bus_open_system</refname>
f00ded93 31 <refname>sd_bus_open_system_with_description</refname>
cd6d5e1c 32 <refname>sd_bus_open_system_remote</refname>
4a2af8d7 33 <refname>sd_bus_open_system_machine</refname>
cd6d5e1c 34
4a2af8d7 35 <refpurpose>Acquire a connection to a system or user bus</refpurpose>
cd6d5e1c
ZJS
36 </refnamediv>
37
38 <refsynopsisdiv>
39 <funcsynopsis>
40 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
41
42 <funcprototype>
4a2af8d7 43 <funcdef>int <function>sd_bus_default</function></funcdef>
8dc385e7 44 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
45 </funcprototype>
46
47 <funcprototype>
4a2af8d7 48 <funcdef>int <function>sd_bus_default_user</function></funcdef>
8dc385e7 49 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
50 </funcprototype>
51
52 <funcprototype>
4a2af8d7 53 <funcdef>int <function>sd_bus_default_system</function></funcdef>
8dc385e7 54 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
55 </funcprototype>
56
57 <funcprototype>
4a2af8d7 58 <funcdef>int <function>sd_bus_open</function></funcdef>
8dc385e7 59 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
60 </funcprototype>
61
f00ded93
ZJS
62 <funcprototype>
63 <funcdef>int <function>sd_bus_open_with_description</function></funcdef>
64 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
65 <paramdef>const char *<parameter>description</parameter></paramdef>
66 </funcprototype>
67
cd6d5e1c 68 <funcprototype>
4a2af8d7 69 <funcdef>int <function>sd_bus_open_user</function></funcdef>
8dc385e7 70 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
71 </funcprototype>
72
f00ded93
ZJS
73 <funcprototype>
74 <funcdef>int <function>sd_bus_open_user_with_description</function></funcdef>
75 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
76 <paramdef>const char *<parameter>description</parameter></paramdef>
77 </funcprototype>
78
cd6d5e1c 79 <funcprototype>
4a2af8d7 80 <funcdef>int <function>sd_bus_open_system</function></funcdef>
8dc385e7 81 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c 82 </funcprototype>
4a2af8d7 83
f00ded93
ZJS
84 <funcprototype>
85 <funcdef>int <function>sd_bus_open_system_with_description</function></funcdef>
86 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
87 <paramdef>const char *<parameter>description</parameter></paramdef>
88 </funcprototype>
89
4a2af8d7
LP
90 <funcprototype>
91 <funcdef>int <function>sd_bus_open_system_remote</function></funcdef>
92 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
93 <paramdef>const char *<parameter>host</parameter></paramdef>
94 </funcprototype>
95
96 <funcprototype>
97 <funcdef>int <function>sd_bus_open_system_machine</function></funcdef>
98 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
99 <paramdef>const char *<parameter>machine</parameter></paramdef>
100 </funcprototype>
101
cd6d5e1c
ZJS
102 </funcsynopsis>
103 </refsynopsisdiv>
104
105 <refsect1>
106 <title>Description</title>
107
4a2af8d7 108 <para><function>sd_bus_default()</function> acquires a bus
850df10a 109 connection object to the user bus when invoked in user context, or
4a2af8d7 110 to the system bus otherwise. The connection object is associated
b898f9bd 111 with the calling thread. Each time the function is invoked from
b938cb90 112 the same thread, the same object is returned, but its reference
b898f9bd 113 count is increased by one, as long as at least one reference is
850df10a
LP
114 kept. When the last reference to the connection is dropped (using
115 the
116 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
117 call), the connection is terminated. Note that the connection is
118 not automatically terminated when the associated thread ends. It
119 is important to drop the last reference to the bus connection
a8eaaee7
JE
120 explicitly before the thread ends, as otherwise, the connection will
121 leak. Also, queued but unread or unwritten messages keep the
b898f9bd 122 bus referenced, see below.</para>
4a2af8d7
LP
123
124 <para><function>sd_bus_default_user()</function> returns a user
b898f9bd 125 bus connection object associated with the calling thread.
4a2af8d7 126 <function>sd_bus_default_system()</function> is similar, but
850df10a
LP
127 connects to the system bus. Note that
128 <function>sd_bus_default()</function> is identical to these two
129 calls, depending on the execution context.</para>
cd6d5e1c 130
4a2af8d7
LP
131 <para><function>sd_bus_open()</function> creates a new,
132 independent bus connection to the user bus when invoked in user
850df10a 133 context, or the system bus
4a2af8d7
LP
134 otherwise. <function>sd_bus_open_user()</function> is similar, but
135 connects only to the user bus.
136 <function>sd_bus_open_system()</function> does the same, but
137 connects to the system bus. In contrast to
138 <function>sd_bus_default()</function>,
a8eaaee7 139 <function>sd_bus_default_user()</function>, and
b938cb90 140 <function>sd_bus_default_system()</function>, these calls return
4a2af8d7
LP
141 new, independent connection objects that are not associated with
142 the invoking thread and are not shared between multiple
143 invocations. It is recommended to share connections per thread to
144 efficiently make use the available resources. Thus, it is
145 recommended to use <function>sd_bus_default()</function>,
a8eaaee7 146 <function>sd_bus_default_user()</function> and
4a2af8d7 147 <function>sd_bus_default_system()</function> to connect to the
ff9b60f3 148 user or system buses.</para>
4a2af8d7 149
f00ded93
ZJS
150 <para><function>sd_bus_open_with_description()</function>,
151 <function>sd_bus_open_user_with_description()</function>, and
152 <function>sd_bus_open_system_with_description()</function> are similar to
153 <function>sd_bus_open()</function>, <function>sd_bus_open_user()</function>, and
154 <function>sd_bus_open_system()</function>, but allow a description string to be set, see
155 <citerefentry><refentrytitle>sd_bus_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
156 <parameter>description</parameter> may be <constant>NULL</constant>, in which case this function
157 is equivalent to <function>sd_bus_open()</function>. This description string is used in log
158 messages about the bus object, and including a "name" for the bus makes them easier to
159 understand. Some messages are emitted during bus initialization, hence using this function is
160 prefereable to setting the description later with
161 <function>sd_bus_open_with_description()</function>. The argument is copied internally and will
162 not be referenced after the function returns.</para>
163
66f756d4 164 <para>If the <varname>$DBUS_SESSION_BUS_ADDRESS</varname> environment
cd6d5e1c 165 variable is set
5aded369 166 (cf. <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
cd6d5e1c
ZJS
167 it will be used as the address of the user bus. This variable can
168 contain multiple addresses separated by <literal>;</literal>. If
169 this variable is not set, a suitable default for the default user
170 D-Bus instance will be used.</para>
171
4a2af8d7
LP
172 <para>If the <varname>$DBUS_SYSTEM_BUS_ADDRESS</varname>
173 environment variable is set, it will be used as the address of the
174 system bus. This variable uses the same syntax as
175 <varname>$DBUS_SESSION_BUS_ADDRESS</varname>. If this variable is
cd6d5e1c
ZJS
176 not set, a suitable default for the default system D-Bus instance
177 will be used.</para>
178
f8f1e666
ZJS
179 <para><function>sd_bus_open_system_remote()</function> connects to the system bus on
180 the specified host using
181 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
182 <parameter>host</parameter> consists of an optional user name followed by the
183 <literal>@</literal> symbol, and the hostname, optionally followed by a
2e6fe090
SL
184 <literal>:</literal> and a port, optionally followed by a
185 <literal>/</literal> and a machine name. If the machine name is given, a connection
f8f1e666
ZJS
186 is created to the system bus in the specified container on the remote machine, and
187 otherwise a connection to the system bus on the specified host is created.</para>
188
189 <para>Note that entering a container is a privileged operation, and will likely only
190 work for the root user on the remote machine.</para>
cd6d5e1c 191
30cd7638 192 <para><function>sd_bus_open_system_machine()</function> connects
174299e3 193 to the system bus in the specified <parameter>machine</parameter>,
4a2af8d7
LP
194 where <parameter>machine</parameter> is the name of a local
195 container. See
cd6d5e1c 196 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
850df10a
LP
197 for more information about the "machine" concept. Note that
198 connections into local containers are only available to privileged
199 processes at this time.</para>
200
201 <para>These calls allocate a bus connection object and initiate
67ad70e4 202 the connection to a well-known bus of some form. An alternative to
850df10a
LP
203 using these high-level calls is to create an unconnected bus
204 object with
205 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>
206 and to connect it with
207 <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
208 </para>
cd6d5e1c 209
cd6d5e1c
ZJS
210 </refsect1>
211
cd6d5e1c
ZJS
212 <refsect1>
213 <title>Reference ownership</title>
850df10a
LP
214 <para>The functions <function>sd_bus_open()</function>,
215 <function>sd_bus_open_user()</function>,
cd6d5e1c
ZJS
216 <function>sd_bus_open_system()</function>,
217 <function>sd_bus_open_system_remote()</function>, and
218 <function>sd_bus_open_system_machine()</function> return a new
b898f9bd
LP
219 connection object and the caller owns the sole reference. When not
220 needed anymore, this reference should be destroyed with
cd6d5e1c
ZJS
221 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
222 </para>
223
4a2af8d7
LP
224 <para>The functions <function>sd_bus_default()</function>,
225 <function>sd_bus_default_user()</function> and
226 <function>sd_bus_default_system()</function> do not necessarily
b898f9bd
LP
227 create a new object, but increase the connection reference of an
228 existing connection object by one. Use
4a2af8d7
LP
229 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
230 to drop the reference.</para>
db03761e 231
1004b2c7
LP
232 <para>Queued but unwritten/unread messages keep a reference to their bus connection object. For this reason, even
233 if an application dropped all references to a bus connection, it might not get destroyed right away. Until all
234 incoming queued messages are read, and until all outgoing unwritten messages are written, the bus object will stay
235 alive. <function>sd_bus_flush()</function> may be used to write all outgoing queued messages so they drop their
236 references. To flush the unread incoming messages, use <function>sd_bus_close()</function>, which will also close
237 the bus connection. When using the default bus logic, it is a good idea to first invoke
238 <function>sd_bus_flush()</function> followed by <function>sd_bus_close()</function> when a thread or process
239 terminates, and thus its bus connection object should be freed.</para>
240
241 <para>Normally, slot objects (as created by
242 <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> and similar
243 calls) keep a reference to their bus connection object, too. Thus, as long as a bus slot object remains referenced
244 its bus object will remain allocated too. Optionally, bus slot objects may be placed in "floating" mode. When in
245 floating mode the life cycle of the bus slot object is bound to the bus object, i.e. when the bus object is freed
246 the bus slot object is automatically unreferenced too. The floating state of a slot object may be controlled
247 explicitly with
248 <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
249 though usually floating bus slot objects are created by passing <constant>NULL</constant> as the
250 <parameter>slot</parameter> parameter of <function>sd_bus_add_match()</function> and related calls, thus indicating
251 that the caller is not directly interested in referencing and managing the bus slot object.</para>
b898f9bd 252
b938cb90 253 <para>The life cycle of the default bus connection should be the
b898f9bd
LP
254 responsibility of the code that creates/owns the thread the
255 default bus connection object is associated with. Library code
256 should neither call <function>sd_bus_flush()</function> nor
257 <function>sd_bus_close()</function> on default bus objects unless
258 it does so in its own private, self-allocated thread. Library code
259 should not use the default bus object in other threads unless it
b938cb90 260 is clear that the program using it will life cycle the bus
b898f9bd
LP
261 connection object and flush and close it before exiting from the
262 thread. In libraries where it is not clear that the calling
b938cb90 263 program will life cycle the bus connection object, it is hence
b898f9bd
LP
264 recommended to use <function>sd_bus_open_system()</function>
265 instead of <function>sd_bus_default_system()</function> and
266 related calls.</para>
267 </refsect1>
268
269 <refsect1>
270 <title>Return Value</title>
271
272 <para>On success, these calls return 0 or a positive
273 integer. On failure, these calls return a negative
274 errno-style error code.</para>
cd6d5e1c
ZJS
275 </refsect1>
276
277 <refsect1>
278 <title>Errors</title>
279
280 <para>Returned errors may indicate the following problems:</para>
281
282 <variablelist>
283
284 <varlistentry>
8474b70c 285 <term><constant>-EINVAL</constant></term>
cd6d5e1c 286
4a2af8d7 287 <listitem><para>The specified parameters are invalid.</para></listitem>
cd6d5e1c
ZJS
288 </varlistentry>
289
290 <varlistentry>
8474b70c 291 <term><constant>-ENOMEM</constant></term>
cd6d5e1c
ZJS
292
293 <listitem><para>Memory allocation failed.</para></listitem>
294 </varlistentry>
295
4a2af8d7
LP
296 <varlistentry>
297 <term><constant>-ESOCKTNOSUPPORT</constant></term>
298
299 <listitem><para>The protocol version required to connect to the selected bus is not supported.</para></listitem>
300 </varlistentry>
cd6d5e1c 301 </variablelist>
4a2af8d7
LP
302
303 <para>In addition, any further connection-related errors may be
304 by returned. See <citerefentry><refentrytitle>sd_bus_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
cd6d5e1c
ZJS
305 </refsect1>
306
7d6b2723 307 <xi:include href="libsystemd-pkgconfig.xml" />
cd6d5e1c
ZJS
308
309 <refsect1>
310 <title>See Also</title>
311
312 <para>
313 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
314 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
315 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
316 <citerefentry><refentrytitle>sd_bus_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
317 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3ba3a79d 318 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
cd6d5e1c
ZJS
319 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
320 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
321 </para>
322 </refsect1>
323
324</refentry>