]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_default.xml
man: document that start limiting of GC'ed units doesn't work (#7337)
[thirdparty/systemd.git] / man / sd_bus_default.xml
CommitLineData
3802a3d3 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
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<!--
5de0ccff 6 This file is part of systemd.
cd6d5e1c 7
5de0ccff 8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
cd6d5e1c 9
5de0ccff
ZJS
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
cd6d5e1c 14
5de0ccff
ZJS
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
cd6d5e1c 19
5de0ccff
ZJS
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
cd6d5e1c
ZJS
22-->
23
48f69d8f 24<refentry id="sd_bus_default">
cd6d5e1c
ZJS
25
26 <refentryinfo>
4a2af8d7 27 <title>sd_bus_default</title>
cd6d5e1c
ZJS
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>A monkey with a typewriter</contrib>
33 <firstname>Zbigniew</firstname>
34 <surname>Jędrzejewski-Szmek</surname>
35 <email>zbyszek@in.waw.pl</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
4a2af8d7 41 <refentrytitle>sd_bus_default</refentrytitle>
cd6d5e1c
ZJS
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
4a2af8d7
LP
46 <refname>sd_bus_default</refname>
47 <refname>sd_bus_default_user</refname>
48 <refname>sd_bus_default_system</refname>
49
50 <refname>sd_bus_open</refname>
cd6d5e1c
ZJS
51 <refname>sd_bus_open_user</refname>
52 <refname>sd_bus_open_system</refname>
53 <refname>sd_bus_open_system_remote</refname>
4a2af8d7 54 <refname>sd_bus_open_system_machine</refname>
cd6d5e1c 55
4a2af8d7 56 <refpurpose>Acquire a connection to a system or user bus</refpurpose>
cd6d5e1c
ZJS
57 </refnamediv>
58
59 <refsynopsisdiv>
60 <funcsynopsis>
61 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
62
63 <funcprototype>
4a2af8d7 64 <funcdef>int <function>sd_bus_default</function></funcdef>
8dc385e7 65 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
66 </funcprototype>
67
68 <funcprototype>
4a2af8d7 69 <funcdef>int <function>sd_bus_default_user</function></funcdef>
8dc385e7 70 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
71 </funcprototype>
72
73 <funcprototype>
4a2af8d7 74 <funcdef>int <function>sd_bus_default_system</function></funcdef>
8dc385e7 75 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
76 </funcprototype>
77
78 <funcprototype>
4a2af8d7 79 <funcdef>int <function>sd_bus_open</function></funcdef>
8dc385e7 80 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
81 </funcprototype>
82
83 <funcprototype>
4a2af8d7 84 <funcdef>int <function>sd_bus_open_user</function></funcdef>
8dc385e7 85 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c
ZJS
86 </funcprototype>
87
88 <funcprototype>
4a2af8d7 89 <funcdef>int <function>sd_bus_open_system</function></funcdef>
8dc385e7 90 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
cd6d5e1c 91 </funcprototype>
4a2af8d7
LP
92
93 <funcprototype>
94 <funcdef>int <function>sd_bus_open_system_remote</function></funcdef>
95 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
96 <paramdef>const char *<parameter>host</parameter></paramdef>
97 </funcprototype>
98
99 <funcprototype>
100 <funcdef>int <function>sd_bus_open_system_machine</function></funcdef>
101 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
102 <paramdef>const char *<parameter>machine</parameter></paramdef>
103 </funcprototype>
104
cd6d5e1c
ZJS
105 </funcsynopsis>
106 </refsynopsisdiv>
107
108 <refsect1>
109 <title>Description</title>
110
4a2af8d7 111 <para><function>sd_bus_default()</function> acquires a bus
850df10a 112 connection object to the user bus when invoked in user context, or
4a2af8d7 113 to the system bus otherwise. The connection object is associated
b898f9bd 114 with the calling thread. Each time the function is invoked from
b938cb90 115 the same thread, the same object is returned, but its reference
b898f9bd 116 count is increased by one, as long as at least one reference is
850df10a
LP
117 kept. When the last reference to the connection is dropped (using
118 the
119 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
120 call), the connection is terminated. Note that the connection is
121 not automatically terminated when the associated thread ends. It
122 is important to drop the last reference to the bus connection
a8eaaee7
JE
123 explicitly before the thread ends, as otherwise, the connection will
124 leak. Also, queued but unread or unwritten messages keep the
b898f9bd 125 bus referenced, see below.</para>
4a2af8d7
LP
126
127 <para><function>sd_bus_default_user()</function> returns a user
b898f9bd 128 bus connection object associated with the calling thread.
4a2af8d7 129 <function>sd_bus_default_system()</function> is similar, but
850df10a
LP
130 connects to the system bus. Note that
131 <function>sd_bus_default()</function> is identical to these two
132 calls, depending on the execution context.</para>
cd6d5e1c 133
4a2af8d7
LP
134 <para><function>sd_bus_open()</function> creates a new,
135 independent bus connection to the user bus when invoked in user
850df10a 136 context, or the system bus
4a2af8d7
LP
137 otherwise. <function>sd_bus_open_user()</function> is similar, but
138 connects only to the user bus.
139 <function>sd_bus_open_system()</function> does the same, but
140 connects to the system bus. In contrast to
141 <function>sd_bus_default()</function>,
a8eaaee7 142 <function>sd_bus_default_user()</function>, and
b938cb90 143 <function>sd_bus_default_system()</function>, these calls return
4a2af8d7
LP
144 new, independent connection objects that are not associated with
145 the invoking thread and are not shared between multiple
146 invocations. It is recommended to share connections per thread to
147 efficiently make use the available resources. Thus, it is
148 recommended to use <function>sd_bus_default()</function>,
a8eaaee7 149 <function>sd_bus_default_user()</function> and
4a2af8d7 150 <function>sd_bus_default_system()</function> to connect to the
ff9b60f3 151 user or system buses.</para>
4a2af8d7 152
66f756d4 153 <para>If the <varname>$DBUS_SESSION_BUS_ADDRESS</varname> environment
cd6d5e1c 154 variable is set
5aded369 155 (cf. <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
cd6d5e1c
ZJS
156 it will be used as the address of the user bus. This variable can
157 contain multiple addresses separated by <literal>;</literal>. If
158 this variable is not set, a suitable default for the default user
159 D-Bus instance will be used.</para>
160
4a2af8d7
LP
161 <para>If the <varname>$DBUS_SYSTEM_BUS_ADDRESS</varname>
162 environment variable is set, it will be used as the address of the
163 system bus. This variable uses the same syntax as
164 <varname>$DBUS_SESSION_BUS_ADDRESS</varname>. If this variable is
cd6d5e1c
ZJS
165 not set, a suitable default for the default system D-Bus instance
166 will be used.</para>
167
f8f1e666
ZJS
168 <para><function>sd_bus_open_system_remote()</function> connects to the system bus on
169 the specified host using
170 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
171 <parameter>host</parameter> consists of an optional user name followed by the
172 <literal>@</literal> symbol, and the hostname, optionally followed by a
173 <literal>:</literal> and a machine name. If the machine name is given, a connection
174 is created to the system bus in the specified container on the remote machine, and
175 otherwise a connection to the system bus on the specified host is created.</para>
176
177 <para>Note that entering a container is a privileged operation, and will likely only
178 work for the root user on the remote machine.</para>
cd6d5e1c 179
30cd7638 180 <para><function>sd_bus_open_system_machine()</function> connects
174299e3 181 to the system bus in the specified <parameter>machine</parameter>,
4a2af8d7
LP
182 where <parameter>machine</parameter> is the name of a local
183 container. See
cd6d5e1c 184 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
850df10a
LP
185 for more information about the "machine" concept. Note that
186 connections into local containers are only available to privileged
187 processes at this time.</para>
188
189 <para>These calls allocate a bus connection object and initiate
67ad70e4 190 the connection to a well-known bus of some form. An alternative to
850df10a
LP
191 using these high-level calls is to create an unconnected bus
192 object with
193 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>
194 and to connect it with
195 <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
196 </para>
cd6d5e1c 197
cd6d5e1c
ZJS
198 </refsect1>
199
cd6d5e1c
ZJS
200 <refsect1>
201 <title>Reference ownership</title>
850df10a
LP
202 <para>The functions <function>sd_bus_open()</function>,
203 <function>sd_bus_open_user()</function>,
cd6d5e1c
ZJS
204 <function>sd_bus_open_system()</function>,
205 <function>sd_bus_open_system_remote()</function>, and
206 <function>sd_bus_open_system_machine()</function> return a new
b898f9bd
LP
207 connection object and the caller owns the sole reference. When not
208 needed anymore, this reference should be destroyed with
cd6d5e1c
ZJS
209 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
210 </para>
211
4a2af8d7
LP
212 <para>The functions <function>sd_bus_default()</function>,
213 <function>sd_bus_default_user()</function> and
214 <function>sd_bus_default_system()</function> do not necessarily
b898f9bd
LP
215 create a new object, but increase the connection reference of an
216 existing connection object by one. Use
4a2af8d7
LP
217 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
218 to drop the reference.</para>
db03761e 219
b898f9bd
LP
220 <para>Queued but unwritten/unread messages also keep a reference
221 to their bus connection object. For this reason, even if an
b938cb90
JE
222 application dropped all references to a bus connection, it might
223 not get destroyed right away. Until all incoming queued
b898f9bd
LP
224 messages are read, and until all outgoing unwritten messages are
225 written, the bus object will stay
226 alive. <function>sd_bus_flush()</function> may be used to write
227 all outgoing queued messages so they drop their references. To
b938cb90 228 flush the unread incoming messages, use
b898f9bd 229 <function>sd_bus_close()</function>, which will also close the bus
b938cb90 230 connection. When using the default bus logic, it is a good idea to
b898f9bd
LP
231 first invoke <function>sd_bus_flush()</function> followed by
232 <function>sd_bus_close()</function> when a thread or process
233 terminates, and thus its bus connection object should be
234 freed.</para>
235
b938cb90 236 <para>The life cycle of the default bus connection should be the
b898f9bd
LP
237 responsibility of the code that creates/owns the thread the
238 default bus connection object is associated with. Library code
239 should neither call <function>sd_bus_flush()</function> nor
240 <function>sd_bus_close()</function> on default bus objects unless
241 it does so in its own private, self-allocated thread. Library code
242 should not use the default bus object in other threads unless it
b938cb90 243 is clear that the program using it will life cycle the bus
b898f9bd
LP
244 connection object and flush and close it before exiting from the
245 thread. In libraries where it is not clear that the calling
b938cb90 246 program will life cycle the bus connection object, it is hence
b898f9bd
LP
247 recommended to use <function>sd_bus_open_system()</function>
248 instead of <function>sd_bus_default_system()</function> and
249 related calls.</para>
250 </refsect1>
251
252 <refsect1>
253 <title>Return Value</title>
254
255 <para>On success, these calls return 0 or a positive
256 integer. On failure, these calls return a negative
257 errno-style error code.</para>
cd6d5e1c
ZJS
258 </refsect1>
259
260 <refsect1>
261 <title>Errors</title>
262
263 <para>Returned errors may indicate the following problems:</para>
264
265 <variablelist>
266
267 <varlistentry>
8474b70c 268 <term><constant>-EINVAL</constant></term>
cd6d5e1c 269
4a2af8d7 270 <listitem><para>The specified parameters are invalid.</para></listitem>
cd6d5e1c
ZJS
271 </varlistentry>
272
273 <varlistentry>
8474b70c 274 <term><constant>-ENOMEM</constant></term>
cd6d5e1c
ZJS
275
276 <listitem><para>Memory allocation failed.</para></listitem>
277 </varlistentry>
278
4a2af8d7
LP
279 <varlistentry>
280 <term><constant>-ESOCKTNOSUPPORT</constant></term>
281
282 <listitem><para>The protocol version required to connect to the selected bus is not supported.</para></listitem>
283 </varlistentry>
cd6d5e1c 284 </variablelist>
4a2af8d7
LP
285
286 <para>In addition, any further connection-related errors may be
287 by returned. See <citerefentry><refentrytitle>sd_bus_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
cd6d5e1c
ZJS
288 </refsect1>
289
290 <refsect1>
291 <title>Notes</title>
292
4a2af8d7
LP
293 <para><function>sd_bus_open_user()</function> and the other
294 functions described here are available as a shared library, which
295 can be compiled and linked to with the
296 <constant>libsystemd</constant> <citerefentry
297 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
cd6d5e1c
ZJS
298 file.</para>
299 </refsect1>
300
301 <refsect1>
302 <title>See Also</title>
303
304 <para>
305 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
306 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
307 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
308 <citerefentry><refentrytitle>sd_bus_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
309 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3ba3a79d 310 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
cd6d5e1c
ZJS
311 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
312 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
313 </para>
314 </refsect1>
315
316</refentry>