]> git.proxmox.com Git - systemd.git/blame - man/sd_bus_default.xml
Imported Upstream version 223
[systemd.git] / man / sd_bus_default.xml
CommitLineData
f47781d8 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
60f067b4
JS
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<!--
e3bff60a 6 This file is part of systemd.
60f067b4 7
e3bff60a 8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
60f067b4 9
e3bff60a
MP
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.
60f067b4 14
e3bff60a
MP
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.
60f067b4 19
e3bff60a
MP
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/>.
60f067b4
JS
22-->
23
86f210e9 24<refentry id="sd_bus_default">
60f067b4
JS
25
26 <refentryinfo>
e3bff60a 27 <title>sd_bus_default</title>
60f067b4
JS
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>
e3bff60a 41 <refentrytitle>sd_bus_default</refentrytitle>
60f067b4
JS
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
e3bff60a
MP
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>
60f067b4
JS
51 <refname>sd_bus_open_user</refname>
52 <refname>sd_bus_open_system</refname>
53 <refname>sd_bus_open_system_remote</refname>
e3bff60a 54 <refname>sd_bus_open_system_machine</refname>
60f067b4 55
e3bff60a 56 <refpurpose>Acquire a connection to a system or user bus</refpurpose>
60f067b4
JS
57 </refnamediv>
58
59 <refsynopsisdiv>
60 <funcsynopsis>
61 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
62
63 <funcprototype>
e3bff60a 64 <funcdef>int <function>sd_bus_default</function></funcdef>
60f067b4
JS
65 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
66 </funcprototype>
67
68 <funcprototype>
e3bff60a 69 <funcdef>int <function>sd_bus_default_user</function></funcdef>
60f067b4
JS
70 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
71 </funcprototype>
72
73 <funcprototype>
e3bff60a 74 <funcdef>int <function>sd_bus_default_system</function></funcdef>
60f067b4
JS
75 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
76 </funcprototype>
77
78 <funcprototype>
e3bff60a 79 <funcdef>int <function>sd_bus_open</function></funcdef>
60f067b4
JS
80 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
81 </funcprototype>
82
83 <funcprototype>
e3bff60a 84 <funcdef>int <function>sd_bus_open_user</function></funcdef>
60f067b4
JS
85 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
86 </funcprototype>
87
88 <funcprototype>
e3bff60a 89 <funcdef>int <function>sd_bus_open_system</function></funcdef>
60f067b4
JS
90 <paramdef>sd_bus **<parameter>bus</parameter></paramdef>
91 </funcprototype>
e3bff60a
MP
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
60f067b4
JS
105 </funcsynopsis>
106 </refsynopsisdiv>
107
108 <refsect1>
109 <title>Description</title>
110
e3bff60a 111 <para><function>sd_bus_default()</function> acquires a bus
fb183854 112 connection object to the user bus when invoked in user context, or
e3bff60a 113 to the system bus otherwise. The connection object is associated
7035cd9e
MP
114 with the calling thread. Each time the function is invoked from
115 the same thread the same object is returned, but its reference
116 count is increased by one, as long as at least one reference is
fb183854
MP
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
123 explicitly before the thread ends or otherwise the connection will
7035cd9e
MP
124 be leaked. Also, queued but unread or unwritten messages keep the
125 bus referenced, see below.</para>
e3bff60a
MP
126
127 <para><function>sd_bus_default_user()</function> returns a user
7035cd9e 128 bus connection object associated with the calling thread.
e3bff60a 129 <function>sd_bus_default_system()</function> is similar, but
fb183854
MP
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>
60f067b4 133
e3bff60a
MP
134 <para><function>sd_bus_open()</function> creates a new,
135 independent bus connection to the user bus when invoked in user
fb183854 136 context, or the system bus
e3bff60a
MP
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>,
142 <function>sd_bus_default_user()</function>,
143 <function>sd_bus_default_system()</function> these calls return
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>,
149 <function>sd_bus_default_user()</function>,
150 <function>sd_bus_default_system()</function> to connect to the
151 user or system buses.</para>
152
60f067b4
JS
153 <para>If the <varname>$DBUS_SESSION_BUS_ADDRESS</varname> environment
154 variable is set
5eef597e 155 (cf. <citerefentry project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
60f067b4
JS
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
e3bff60a
MP
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
60f067b4
JS
165 not set, a suitable default for the default system D-Bus instance
166 will be used.</para>
167
168 <para><function>sd_bus_open_system_remote()</function> connects to
169 the system bus on the specified <parameter>host</parameter> using
fb183854
MP
170 <citerefentry
171 project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>. <parameter>host</parameter>
172 consists of an optional user name followed by the
173 <literal>@</literal> symbol, and the hostname.
60f067b4
JS
174 </para>
175
fb183854 176 <para><function>sd_bus_open_system_machine()</function> connects
f47781d8 177 to the system bus in the specified <parameter>machine</parameter>,
e3bff60a
MP
178 where <parameter>machine</parameter> is the name of a local
179 container. See
60f067b4 180 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
fb183854
MP
181 for more information about the "machine" concept. Note that
182 connections into local containers are only available to privileged
183 processes at this time.</para>
184
185 <para>These calls allocate a bus connection object and initiate
186 the connection to a well-known bus of some form. An alternative to
187 using these high-level calls is to create an unconnected bus
188 object with
189 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>
190 and to connect it with
191 <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
192 </para>
60f067b4 193
60f067b4
JS
194 </refsect1>
195
60f067b4
JS
196 <refsect1>
197 <title>Reference ownership</title>
fb183854
MP
198 <para>The functions <function>sd_bus_open()</function>,
199 <function>sd_bus_open_user()</function>,
60f067b4
JS
200 <function>sd_bus_open_system()</function>,
201 <function>sd_bus_open_system_remote()</function>, and
202 <function>sd_bus_open_system_machine()</function> return a new
7035cd9e
MP
203 connection object and the caller owns the sole reference. When not
204 needed anymore, this reference should be destroyed with
60f067b4
JS
205 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
206 </para>
207
e3bff60a
MP
208 <para>The functions <function>sd_bus_default()</function>,
209 <function>sd_bus_default_user()</function> and
210 <function>sd_bus_default_system()</function> do not necessarily
7035cd9e
MP
211 create a new object, but increase the connection reference of an
212 existing connection object by one. Use
e3bff60a
MP
213 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
214 to drop the reference.</para>
7035cd9e
MP
215
216 <para>Queued but unwritten/unread messages also keep a reference
217 to their bus connection object. For this reason, even if an
218 application dropped all references to a bus connection it might
219 not get destroyed right-away. Until all incoming queued
220 messages are read, and until all outgoing unwritten messages are
221 written, the bus object will stay
222 alive. <function>sd_bus_flush()</function> may be used to write
223 all outgoing queued messages so they drop their references. To
224 flush the unread incoming messages use
225 <function>sd_bus_close()</function>, which will also close the bus
226 connection. When using the default bus logic it is a good idea to
227 first invoke <function>sd_bus_flush()</function> followed by
228 <function>sd_bus_close()</function> when a thread or process
229 terminates, and thus its bus connection object should be
230 freed.</para>
231
232 <para>The life-cycle of the default bus connection should be the
233 responsibility of the code that creates/owns the thread the
234 default bus connection object is associated with. Library code
235 should neither call <function>sd_bus_flush()</function> nor
236 <function>sd_bus_close()</function> on default bus objects unless
237 it does so in its own private, self-allocated thread. Library code
238 should not use the default bus object in other threads unless it
239 is clear that the program using it will life-cycle the bus
240 connection object and flush and close it before exiting from the
241 thread. In libraries where it is not clear that the calling
242 program will life-cycle the bus connection object it is hence
243 recommended to use <function>sd_bus_open_system()</function>
244 instead of <function>sd_bus_default_system()</function> and
245 related calls.</para>
246 </refsect1>
247
248 <refsect1>
249 <title>Return Value</title>
250
251 <para>On success, these calls return 0 or a positive
252 integer. On failure, these calls return a negative
253 errno-style error code.</para>
60f067b4
JS
254 </refsect1>
255
256 <refsect1>
257 <title>Errors</title>
258
259 <para>Returned errors may indicate the following problems:</para>
260
261 <variablelist>
262
263 <varlistentry>
5eef597e 264 <term><constant>-EINVAL</constant></term>
60f067b4 265
e3bff60a 266 <listitem><para>The specified parameters are invalid.</para></listitem>
60f067b4
JS
267 </varlistentry>
268
269 <varlistentry>
5eef597e 270 <term><constant>-ENOMEM</constant></term>
60f067b4
JS
271
272 <listitem><para>Memory allocation failed.</para></listitem>
273 </varlistentry>
274
e3bff60a
MP
275 <varlistentry>
276 <term><constant>-ESOCKTNOSUPPORT</constant></term>
277
278 <listitem><para>The protocol version required to connect to the selected bus is not supported.</para></listitem>
279 </varlistentry>
60f067b4 280 </variablelist>
e3bff60a
MP
281
282 <para>In addition, any further connection-related errors may be
283 by returned. See <citerefentry><refentrytitle>sd_bus_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
60f067b4
JS
284 </refsect1>
285
286 <refsect1>
287 <title>Notes</title>
288
e3bff60a
MP
289 <para><function>sd_bus_open_user()</function> and the other
290 functions described here are available as a shared library, which
291 can be compiled and linked to with the
292 <constant>libsystemd</constant> <citerefentry
293 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
60f067b4
JS
294 file.</para>
295 </refsect1>
296
297 <refsect1>
298 <title>See Also</title>
299
300 <para>
301 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
302 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
303 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
304 <citerefentry><refentrytitle>sd_bus_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
305 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
e3bff60a 306 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
60f067b4
JS
307 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
308 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
309 </para>
310 </refsect1>
311
312</refentry>