]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_bus_default.xml
hwdb: Add accelerometer orientation quirk for the PoV TAB-P1006W-232-3G
[thirdparty/systemd.git] / man / sd_bus_default.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7 -->
8
9 <refentry id="sd_bus_default" xmlns:xi="http://www.w3.org/2001/XInclude">
10
11 <refentryinfo>
12 <title>sd_bus_default</title>
13 <productname>systemd</productname>
14 </refentryinfo>
15
16 <refmeta>
17 <refentrytitle>sd_bus_default</refentrytitle>
18 <manvolnum>3</manvolnum>
19 </refmeta>
20
21 <refnamediv>
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>
27 <refname>sd_bus_open_with_description</refname>
28 <refname>sd_bus_open_user</refname>
29 <refname>sd_bus_open_user_with_description</refname>
30 <refname>sd_bus_open_system</refname>
31 <refname>sd_bus_open_system_with_description</refname>
32 <refname>sd_bus_open_system_remote</refname>
33 <refname>sd_bus_open_system_machine</refname>
34
35 <refpurpose>Acquire a connection to a system or user bus</refpurpose>
36 </refnamediv>
37
38 <refsynopsisdiv>
39 <funcsynopsis>
40 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
41
42 <funcprototype>
43 <funcdef>int <function>sd_bus_default</function></funcdef>
44 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
45 </funcprototype>
46
47 <funcprototype>
48 <funcdef>int <function>sd_bus_default_user</function></funcdef>
49 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
50 </funcprototype>
51
52 <funcprototype>
53 <funcdef>int <function>sd_bus_default_system</function></funcdef>
54 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
55 </funcprototype>
56
57 <funcprototype>
58 <funcdef>int <function>sd_bus_open</function></funcdef>
59 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
60 </funcprototype>
61
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
68 <funcprototype>
69 <funcdef>int <function>sd_bus_open_user</function></funcdef>
70 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
71 </funcprototype>
72
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
79 <funcprototype>
80 <funcdef>int <function>sd_bus_open_system</function></funcdef>
81 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
82 </funcprototype>
83
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
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
102 </funcsynopsis>
103 </refsynopsisdiv>
104
105 <refsect1>
106 <title>Description</title>
107
108 <para><function>sd_bus_default()</function> acquires a bus
109 connection object to the user bus when invoked in user context, or
110 to the system bus otherwise. The connection object is associated
111 with the calling thread. Each time the function is invoked from
112 the same thread, the same object is returned, but its reference
113 count is increased by one, as long as at least one reference is
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
120 explicitly before the thread ends, as otherwise, the connection will
121 leak. Also, queued but unread or unwritten messages keep the
122 bus referenced, see below.</para>
123
124 <para><function>sd_bus_default_user()</function> returns a user
125 bus connection object associated with the calling thread.
126 <function>sd_bus_default_system()</function> is similar, but
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>
130
131 <para><function>sd_bus_open()</function> creates a new,
132 independent bus connection to the user bus when invoked in user
133 context, or the system bus
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>,
139 <function>sd_bus_default_user()</function>, and
140 <function>sd_bus_default_system()</function>, these calls return
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>,
146 <function>sd_bus_default_user()</function> and
147 <function>sd_bus_default_system()</function> to connect to the
148 user or system buses.</para>
149
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
164 <para>If the <varname>$DBUS_SESSION_BUS_ADDRESS</varname> environment
165 variable is set
166 (cf. <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
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
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
176 not set, a suitable default for the default system D-Bus instance
177 will be used.</para>
178
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
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
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>
191
192 <para><function>sd_bus_open_system_machine()</function> connects
193 to the system bus in the specified <parameter>machine</parameter>,
194 where <parameter>machine</parameter> is the name of a local
195 container. See
196 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
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
202 the connection to a well-known bus of some form. An alternative to
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>
209
210 </refsect1>
211
212 <refsect1>
213 <title>Reference ownership</title>
214 <para>The functions <function>sd_bus_open()</function>,
215 <function>sd_bus_open_user()</function>,
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
219 connection object and the caller owns the sole reference. When not
220 needed anymore, this reference should be destroyed with
221 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
222 </para>
223
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
227 create a new object, but increase the connection reference of an
228 existing connection object by one. Use
229 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
230 to drop the reference.</para>
231
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>
252
253 <para>The life cycle of the default bus connection should be the
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
260 is clear that the program using it will life cycle the bus
261 connection object and flush and close it before exiting from the
262 thread. In libraries where it is not clear that the calling
263 program will life cycle the bus connection object, it is hence
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>
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>
285 <term><constant>-EINVAL</constant></term>
286
287 <listitem><para>The specified parameters are invalid.</para></listitem>
288 </varlistentry>
289
290 <varlistentry>
291 <term><constant>-ENOMEM</constant></term>
292
293 <listitem><para>Memory allocation failed.</para></listitem>
294 </varlistentry>
295
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>
301 </variablelist>
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>
305 </refsect1>
306
307 <xi:include href="libsystemd-pkgconfig.xml" />
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>,
318 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
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>