summaryrefslogtreecommitdiff
path: root/man/sd_bus_default.3
blob: 9a73d06711a6c3b8cf29c3e15c346e19ef13e453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'\" t
.TH "SD_BUS_DEFAULT" "3" "" "systemd 221" "sd_bus_default"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_bus_default, sd_bus_default_user, sd_bus_default_system, sd_bus_open, sd_bus_open_user, sd_bus_open_system, sd_bus_open_system_remote, sd_bus_open_system_machine \- Acquire a connection to a system or user bus
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_bus_default('u
.BI "int sd_bus_default(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_default_user('u
.BI "int sd_bus_default_user(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_default_system('u
.BI "int sd_bus_default_system(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_open('u
.BI "int sd_bus_open(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_open_user('u
.BI "int sd_bus_open_user(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_open_system('u
.BI "int sd_bus_open_system(sd_bus\ **" "bus" ");"
.HP \w'int\ sd_bus_open_system_remote('u
.BI "int sd_bus_open_system_remote(sd_bus\ **" "bus" ", const\ char\ *" "host" ");"
.HP \w'int\ sd_bus_open_system_machine('u
.BI "int sd_bus_open_system_machine(sd_bus\ **" "bus" ", const\ char\ *" "machine" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_default()\fR
acquires a bus connection object to the user bus when invoked in user context or to the system bus otherwise\&. The connection object is associated to the calling thread\&. Each time the function is invoked from the same thread the same object is returned, but its reference count increased by one, as long as at least one reference is kept\&. When the last reference to the connection is dropped (using the
\fBsd_bus_unref()\fR
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 or otherwise the connection will be leaked\&.
.PP
\fBsd_bus_default_user()\fR
returns a user bus connection object associated to the calling thread\&.
\fBsd_bus_default_system()\fR
is similar, but connects to the system bus\&.
.PP
\fBsd_bus_open()\fR
creates a new, independent bus connection to the user bus when invoked in user context or the system bus otherwise\&.
\fBsd_bus_open_user()\fR
is similar, but connects only to the user bus\&.
\fBsd_bus_open_system()\fR
does the same, but connects to the system bus\&. In contrast to
\fBsd_bus_default()\fR,
\fBsd_bus_default_user()\fR,
\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
\fBsd_bus_default()\fR,
\fBsd_bus_default_user()\fR,
\fBsd_bus_default_system()\fR
to connect to the user or system buses\&.
.PP
If the
\fI$DBUS_SESSION_BUS_ADDRESS\fR
environment variable is set (cf\&.
\fBenviron\fR(7)), it will be used as the address of the user bus\&. This variable can contain multiple addresses separated by
";"\&. If this variable is not set, a suitable default for the default user D\-Bus instance will be used\&.
.PP
If the
\fI$DBUS_SYSTEM_BUS_ADDRESS\fR
environment variable is set, it will be used as the address of the system bus\&. This variable uses the same syntax as
\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\&.
.PP
\fBsd_bus_open_system_remote()\fR
connects to the system bus on the specified
\fIhost\fR
using SSH\&.
\fIhost\fR
consists of an optional user name followed by the
"@"
symbol, and the hostname\&.
.PP
\fBsd_bus_open_system_container()\fR
connects to the system bus in the specified
\fImachine\fR, where
\fImachine\fR
is the name of a local container\&. See
\fBmachinectl\fR(1)
for more information about "machines"\&.
.SH "RETURN VALUE"
.PP
On success, these calls return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
.SH "REFERENCE OWNERSHIP"
.PP
The functions
\fBsd_bus_open_user()\fR,
\fBsd_bus_open()\fR,
\fBsd_bus_open_system()\fR,
\fBsd_bus_open_system_remote()\fR, and
\fBsd_bus_open_system_machine()\fR
return a new object and the caller owns the sole reference\&. When not needed anymore, this reference should be destroyed with
\fBsd_bus_unref\fR(3)\&.
.PP
The functions
\fBsd_bus_default()\fR,
\fBsd_bus_default_user()\fR
and
\fBsd_bus_default_system()\fR
do not necessarily create a new object, but increase the connection reference by one\&. Use
\fBsd_bus_unref\fR(3)
to drop the reference\&.
.SH "ERRORS"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
The specified parameters are invalid\&.
.RE
.PP
\fB\-ENOMEM\fR
.RS 4
Memory allocation failed\&.
.RE
.PP
\fB\-ESOCKTNOSUPPORT\fR
.RS 4
The protocol version required to connect to the selected bus is not supported\&.
.RE
.PP
In addition, any further connection\-related errors may be by returned\&. See
\fBsd_bus_send\fR(3)\&.
.SH "NOTES"
.PP
\fBsd_bus_open_user()\fR
and the other functions described here are available as a shared library, which can be compiled and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-bus\fR(3),
\fBsd_bus_new\fR(3),
\fBsd_bus_ref\fR(3),
\fBsd_bus_unref\fR(3),
\fBssh\fR(1),
\fBsystemd-machined.service\fR(8),
\fBmachinectl\fR(1)