Debian Codegraph @

upstream/debian-unstable/man3/sd_bus_default.3

raw
1 '\" t
2 .TH "SD_BUS_DEFAULT" "3" "" "systemd 261~rc3" "sd_bus_default"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_bus_default, sd_bus_default_user, sd_bus_default_system, sd_bus_open, sd_bus_open_with_description, sd_bus_open_user, sd_bus_open_user_with_description, sd_bus_open_user_machine, sd_bus_open_system, sd_bus_open_system_with_description, sd_bus_open_system_remote, sd_bus_open_system_machine \- Acquire a connection to a system or user bus
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-bus\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_bus_default('u
32 .BI "int sd_bus_default(sd_bus\ **" "bus" ");"
33 .HP \w'int\ sd_bus_default_user('u
34 .BI "int sd_bus_default_user(sd_bus\ **" "bus" ");"
35 .HP \w'int\ sd_bus_default_system('u
36 .BI "int sd_bus_default_system(sd_bus\ **" "bus" ");"
37 .HP \w'int\ sd_bus_open('u
38 .BI "int sd_bus_open(sd_bus\ **" "bus" ");"
39 .HP \w'int\ sd_bus_open_with_description('u
40 .BI "int sd_bus_open_with_description(sd_bus\ **" "bus" ", const\ char\ *" "description" ");"
41 .HP \w'int\ sd_bus_open_user('u
42 .BI "int sd_bus_open_user(sd_bus\ **" "bus" ");"
43 .HP \w'int\ sd_bus_open_user_with_description('u
44 .BI "int sd_bus_open_user_with_description(sd_bus\ **" "bus" ", const\ char\ *" "description" ");"
45 .HP \w'int\ sd_bus_open_user_machine('u
46 .BI "int sd_bus_open_user_machine(sd_bus\ **" "bus" ", const\ char\ *" "machine" ");"
47 .HP \w'int\ sd_bus_open_system('u
48 .BI "int sd_bus_open_system(sd_bus\ **" "bus" ");"
49 .HP \w'int\ sd_bus_open_system_with_description('u
50 .BI "int sd_bus_open_system_with_description(sd_bus\ **" "bus" ", const\ char\ *" "description" ");"
51 .HP \w'int\ sd_bus_open_system_remote('u
52 .BI "int sd_bus_open_system_remote(sd_bus\ **" "bus" ", const\ char\ *" "host" ");"
53 .HP \w'int\ sd_bus_open_system_machine('u
54 .BI "int sd_bus_open_system_machine(sd_bus\ **" "bus" ", const\ char\ *" "machine" ");"
55 .SH "DESCRIPTION"
56 .PP
57 \fBsd_bus_default()\fR
58 acquires a bus connection object to the user bus when invoked from within a user slice (any session under
59 "user\-*\&.slice", e\&.g\&.:
60 "user@1000\&.service"), or to the system bus otherwise\&. The connection object is associated with the calling thread\&. Each time the function is invoked from the same thread, the same object is returned, but its reference count is increased by one, as long as at least one reference is kept\&. When the last reference to the connection is dropped (using the
61 \fBsd_bus_unref\fR(3)
62 call), the connection is terminated\&. Note that the connection is not automatically terminated when the associated thread ends\&. It is important to drop the last reference to the bus connection explicitly before the thread ends, as otherwise, the connection will leak\&. Also, queued but unread or unwritten messages keep the bus referenced, see below\&.
63 .PP
64 \fBsd_bus_default_user()\fR
65 returns a user bus connection object associated with the calling thread\&.
66 \fBsd_bus_default_system()\fR
67 is similar, but connects to the system bus\&. Note that
68 \fBsd_bus_default()\fR
69 is identical to these two calls, depending on the execution context\&.
70 .PP
71 \fBsd_bus_open()\fR
72 creates a new, independent bus connection to the user bus when invoked in user context, or the system bus otherwise\&.
73 \fBsd_bus_open_user()\fR
74 is similar, but connects only to the user bus\&.
75 \fBsd_bus_open_system()\fR
76 does the same, but connects to the system bus\&. In contrast to
77 \fBsd_bus_default()\fR,
78 \fBsd_bus_default_user()\fR, and
79 \fBsd_bus_default_system()\fR, these calls return new, independent connection objects that are not associated with the invoking thread and are not shared between multiple invocations\&. It is recommended to share connections per thread to efficiently make use the available resources\&. Thus, it is recommended to use
80 \fBsd_bus_default()\fR,
81 \fBsd_bus_default_user()\fR
82 and
83 \fBsd_bus_default_system()\fR
84 to connect to the user or system buses\&.
85 .PP
86 \fBsd_bus_open_with_description()\fR,
87 \fBsd_bus_open_user_with_description()\fR, and
88 \fBsd_bus_open_system_with_description()\fR
89 are similar to
90 \fBsd_bus_open()\fR,
91 \fBsd_bus_open_user()\fR, and
92 \fBsd_bus_open_system()\fR, but allow a description string to be set, see
93 \fBsd_bus_set_description\fR(3)\&.
94 \fIdescription\fR
95 may be
96 \fBNULL\fR, in which case this function is equivalent to
97 \fBsd_bus_open()\fR\&. This description string is used in log messages about the bus object, and including a "name" for the bus makes them easier to understand\&. Some messages are emitted during bus initialization, hence using this function is preferable to setting the description later with
98 \fBsd_bus_open_with_description()\fR\&. The argument is copied internally and will not be referenced after the function returns\&.
99 .PP
100 If the
101 \fI$DBUS_SESSION_BUS_ADDRESS\fR
102 environment variable is set (cf\&.
103 \fBenviron\fR(7)), it will be used as the address of the user bus\&. This variable can contain multiple addresses separated by
104 ";"\&. If this variable is not set, a suitable default for the default user D\-Bus instance will be used\&.
105 .PP
106 If the
107 \fI$DBUS_SYSTEM_BUS_ADDRESS\fR
108 environment variable is set, it will be used as the address of the system bus\&. This variable uses the same syntax as
109 \fI$DBUS_SESSION_BUS_ADDRESS\fR\&. If this variable is not set, a suitable default for the default system D\-Bus instance will be used\&.
110 .PP
111 \fBsd_bus_open_system_remote()\fR
112 connects to the system bus on the specified host using
113 \fBssh\fR(1)\&.
114 \fIhost\fR
115 consists of an optional user name followed by the
116 "@"
117 symbol, and the hostname, optionally followed by a
118 ":"
119 and a port, optionally followed by a
120 "/"
121 and a machine name\&. If the machine name is given, a connection is created to the system bus in the specified container on the remote machine, and otherwise a connection to the system bus on the specified host is created\&.
122 .PP
123 Note that entering a container is a privileged operation, and will likely only work for the root user on the remote machine\&.
124 .PP
125 \fBsd_bus_open_system_machine()\fR
126 connects to the system bus in the specified
127 \fImachine\fR, where
128 \fImachine\fR
129 is the name of a local container, possibly prefixed by a user name and a separating
130 "@"\&. If the container name is specified as the special string
131 "\&.host"
132 the connection is made to the local system\&. This is useful to connect to the local system bus as specific user, e\&.g\&.
133 "foobar@\&.host"
134 to connect to the local system bus as local user
135 "foobar"\&. If the
136 "@"
137 syntax is used either the left\-hand side or the right\-hand side may be omitted (but not both) in which case the local user name or
138 "\&.host"
139 is implied\&. If the
140 "@"
141 syntax is not used the connection is always made as root user\&. See
142 \fBsd_bus_set_address\fR(3)
143 for a description of the address syntax, and
144 \fBmachinectl\fR(1)
145 for more information about the "machine" concept\&. Note that connections into local containers are only available to privileged processes at this time\&.
146 .PP
147 \fBsd_bus_open_user_machine()\fR
148 is similar to
149 \fBsd_bus_open_system_machine()\fR, but connects to the user bus of the root user, or if the
150 "@"
151 syntax is used, of the specified user\&.
152 .PP
153 These calls allocate a bus connection object and initiate the connection to a well\-known bus of some form\&. An alternative to using these high\-level calls is to create an unconnected bus object with
154 \fBsd_bus_new\fR(3)
155 and to connect it with
156 \fBsd_bus_start\fR(3)\&.
157 .SH "REFERENCE OWNERSHIP"
158 .PP
159 The functions
160 \fBsd_bus_open()\fR,
161 \fBsd_bus_open_user()\fR,
162 \fBsd_bus_open_user_machine()\fR,
163 \fBsd_bus_open_system()\fR,
164 \fBsd_bus_open_system_remote()\fR, and
165 \fBsd_bus_open_system_machine()\fR
166 return a new connection object and the caller owns the sole reference\&. When not needed anymore, this reference should be destroyed with
167 \fBsd_bus_unref\fR(3)\&.
168 .PP
169 The functions
170 \fBsd_bus_default()\fR,
171 \fBsd_bus_default_user()\fR
172 and
173 \fBsd_bus_default_system()\fR
174 do not necessarily create a new object, but increase the connection reference of an existing connection object by one\&. Use
175 \fBsd_bus_unref\fR(3)
176 to drop the reference\&.
177 .PP
178 Queued but unwritten/unread messages keep a reference to their bus connection object\&. For this reason, even if an application dropped all references to a bus connection, it might not get destroyed right away\&. Until all incoming queued messages are read, and until all outgoing unwritten messages are written, the bus object will stay alive\&.
179 \fBsd_bus_flush()\fR
180 may be used to write all outgoing queued messages so they drop their references\&. To flush the unread incoming messages, use
181 \fBsd_bus_close()\fR, which will also close the bus connection\&. When using the default bus logic, it is a good idea to first invoke
182 \fBsd_bus_flush()\fR
183 followed by
184 \fBsd_bus_close()\fR
185 when a thread or process terminates, and thus its bus connection object should be freed\&.
186 .PP
187 Normally, slot objects (as created by
188 \fBsd_bus_add_match\fR(3)
189 and similar calls) keep a reference to their bus connection object, too\&. Thus, as long as a bus slot object remains referenced its bus object will remain allocated too\&. Optionally, bus slot objects may be placed in "floating" mode\&. When in floating mode the life cycle of the bus slot object is bound to the bus object, i\&.e\&. when the bus object is freed the bus slot object is automatically unreferenced too\&. The floating state of a slot object may be controlled explicitly with
190 \fBsd_bus_slot_set_floating\fR(3), though usually floating bus slot objects are created by passing
191 \fBNULL\fR
192 as the
193 \fIslot\fR
194 parameter of
195 \fBsd_bus_add_match()\fR
196 and related calls, thus indicating that the caller is not directly interested in referencing and managing the bus slot object\&.
197 .PP
198 The life cycle of the default bus connection should be the responsibility of the code that creates/owns the thread the default bus connection object is associated with\&. Library code should neither call
199 \fBsd_bus_flush()\fR
200 nor
201 \fBsd_bus_close()\fR
202 on default bus objects unless it does so in its own private, self\-allocated thread\&. Library code should not use the default bus object in other threads unless it is clear that the program using it will life cycle the bus connection object and flush and close it before exiting from the thread\&. In libraries where it is not clear that the calling program will life cycle the bus connection object, it is hence recommended to use
203 \fBsd_bus_open_system()\fR
204 instead of
205 \fBsd_bus_default_system()\fR
206 and related calls\&.
207 .SH "RETURN VALUE"
208 .PP
209 On success, these calls return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
210 .SS "Errors"
211 .PP
212 Returned errors may indicate the following problems:
213 .PP
214 \fB\-EINVAL\fR
215 .RS 4
216 The specified parameters are invalid\&.
217 .RE
218 .PP
219 \fB\-ENOMEDIUM\fR
220 .RS 4
221 The requested bus type is not available because of invalid environment (for example the user session bus is not available because
222 \fI$XDG_RUNTIME_DIR\fR
223 is not set)\&.
224 .RE
225 .PP
226 \fB\-ENOMEM\fR
227 .RS 4
228 Memory allocation failed\&.
229 .RE
230 .PP
231 \fB\-ESOCKTNOSUPPORT\fR
232 .RS 4
233 The protocol version required to connect to the selected bus is not supported\&.
234 .RE
235 .PP
236 In addition, other connection\-related errors may be returned\&. See
237 \fBsd_bus_send\fR(3)\&.
238 .SH "NOTES"
239 .PP
240 Functions described here are available as a shared library, which can be compiled against and linked to with the
241 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
242 file\&.
243 .PP
244 The code described here uses
245 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
246 \fBsetenv\fR(3)
247 from a parallel thread\&. It is recommended to only do calls to
248 \fBsetenv()\fR
249 from an early phase of the program when no other threads have been started\&.
250 .SH "HISTORY"
251 .PP
252 \fBsd_bus_default()\fR,
253 \fBsd_bus_default_user()\fR,
254 \fBsd_bus_default_system()\fR,
255 \fBsd_bus_open()\fR,
256 \fBsd_bus_open_user()\fR,
257 \fBsd_bus_open_system()\fR,
258 \fBsd_bus_open_system_remote()\fR, and
259 \fBsd_bus_open_system_machine()\fR
260 were added in version 221\&.
261 .PP
262 \fBsd_bus_open_with_description()\fR,
263 \fBsd_bus_open_user_with_description()\fR, and
264 \fBsd_bus_open_system_with_description()\fR
265 were added in version 239\&.
266 .PP
267 \fBsd_bus_open_user_machine()\fR
268 was added in version 248\&.
269 .SH "SEE ALSO"
270 .PP
271 \fBsystemd\fR(1), \fBsd-bus\fR(3), \fBsd_bus_new\fR(3), \fBsd_bus_ref\fR(3), \fBsd_bus_unref\fR(3), \fBsd_bus_close\fR(3), \fBssh\fR(1), \fBsystemd-machined.service\fR(8), \fBmachinectl\fR(1)