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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
'\" t
.TH "SD_BUS_NEW" "3" "" "systemd 255" "sd_bus_new"
.\" -----------------------------------------------------------------
.\" * 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_new, sd_bus_ref, sd_bus_unref, sd_bus_unrefp, sd_bus_close_unref, sd_bus_close_unrefp, sd_bus_flush_close_unref, sd_bus_flush_close_unrefp \- Create a new bus object and create or destroy references to it
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_bus_new('u
.BI "int sd_bus_new(sd_bus\ **" "bus" ");"
.HP \w'sd_bus\ *sd_bus_ref('u
.BI "sd_bus *sd_bus_ref(sd_bus\ *" "bus" ");"
.HP \w'sd_bus\ *sd_bus_unref('u
.BI "sd_bus *sd_bus_unref(sd_bus\ *" "bus" ");"
.HP \w'sd_bus\ *sd_bus_close_unref('u
.BI "sd_bus *sd_bus_close_unref(sd_bus\ *" "bus" ");"
.HP \w'sd_bus\ *sd_bus_flush_close_unref('u
.BI "sd_bus *sd_bus_flush_close_unref(sd_bus\ *" "bus" ");"
.HP \w'void\ sd_bus_unrefp('u
.BI "void sd_bus_unrefp(sd_bus\ **" "busp" ");"
.HP \w'void\ sd_bus_close_unrefp('u
.BI "void sd_bus_close_unrefp(sd_bus\ **" "busp" ");"
.HP \w'void\ sd_bus_flush_close_unrefp('u
.BI "void sd_bus_flush_close_unrefp(sd_bus\ **" "busp" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_new()\fR
creates a new bus object\&. This object is reference\-counted, and will be destroyed when all references are gone\&. Initially, the caller of this function owns the sole reference and the bus object will not be connected to any bus\&. To connect it to a bus, make sure to set an address with
\fBsd_bus_set_address\fR(3)
or a related call, and then start the connection with
\fBsd_bus_start\fR(3)\&.
.PP
In most cases, it is better to use
\fBsd_bus_default_user\fR(3),
\fBsd_bus_default_system\fR(3)
or related calls instead of the more low\-level
\fBsd_bus_new()\fR
and
\fBsd_bus_start()\fR\&. The higher\-level functions not only allocate a bus object but also start the connection to a well\-known bus in a single function call\&.
.PP
\fBsd_bus_ref()\fR
increases the reference counter of
\fIbus\fR
by one\&.
.PP
\fBsd_bus_unref()\fR
decreases the reference counter of
\fIbus\fR
by one\&. Once the reference count has dropped to zero,
\fIbus\fR
is destroyed and cannot be used anymore, so further calls to
\fBsd_bus_ref()\fR
or
\fBsd_bus_unref()\fR
are illegal\&.
.PP
\fBsd_bus_unrefp()\fR
is similar to
\fBsd_bus_unref()\fR
but takes a pointer to a pointer to an
\fBsd_bus\fR
object\&. This call is useful in conjunction with GCC\*(Aqs and LLVM\*(Aqs
\m[blue]\fBClean\-up Variable Attribute\fR\m[]\&\s-2\u[1]\d\s+2\&. Note that this function is defined as an inline function\&. Use a declaration like the following, in order to allocate a bus object that is freed automatically as the code block is left:
.sp
.if n \{\
.RS 4
.\}
.nf
{
__attribute__((cleanup(sd_bus_unrefp))) sd_bus *bus = NULL;
int r;
\&...
r = sd_bus_default(&bus);
if (r < 0) {
errno = \-r;
fprintf(stderr, "Failed to allocate bus: %m\en");
}
\&...
}
.fi
.if n \{\
.RE
.\}
.PP
\fBsd_bus_ref()\fR
and
\fBsd_bus_unref()\fR
execute no operation if the argument is
\fBNULL\fR\&.
\fBsd_bus_unrefp()\fR
will first dereference its argument, which must not be
\fBNULL\fR, and will execute no operation if
\fIthat\fR
is
\fBNULL\fR\&.
.PP
\fBsd_bus_close_unref()\fR
is similar to
\fBsd_bus_unref()\fR, but first executes
\fBsd_bus_close\fR(3), ensuring that the connection is terminated before the reference to the connection is dropped and possibly the object freed\&.
.PP
\fBsd_bus_flush_close_unref()\fR
is similar to
\fBsd_bus_unref()\fR, but first executes
\fBsd_bus_flush\fR(3)
as well as
\fBsd_bus_close\fR(3), ensuring that any pending messages are synchronously flushed out before the reference to the connection is dropped and possibly the object freed\&. This call is particularly useful immediately before exiting from a program as it ensures that any pending outgoing messages are written out, and unprocessed but queued incoming messages released before the connection is terminated and released\&.
.PP
\fBsd_bus_close_unrefp()\fR
is similar to
\fBsd_bus_close_unref()\fR, but may be used in GCC\*(Aqs and LLVM\*(Aqs Clean\-up Variable Attribute, see above\&. Similarly,
\fBsd_bus_flush_close_unrefp()\fR
is similar to
\fBsd_bus_flush_close_unref()\fR\&.
.SH "RETURN VALUE"
.PP
On success,
\fBsd_bus_new()\fR
returns 0 or a positive integer\&. On failure, it returns a negative errno\-style error code\&.
.PP
\fBsd_bus_ref()\fR
always returns the argument\&.
.PP
\fBsd_bus_unref()\fR
and
\fBsd_bus_flush_close_unref()\fR
always return
\fBNULL\fR\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-ENOMEM\fR
.RS 4
Memory allocation failed\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\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
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_bus_new()\fR,
\fBsd_bus_ref()\fR, and
\fBsd_bus_unref()\fR
were added in version 209\&.
.PP
\fBsd_bus_unrefp()\fR
was added in version 229\&.
.PP
\fBsd_bus_flush_close_unref()\fR
and
\fBsd_bus_flush_close_unrefp()\fR
were added in version 240\&.
.PP
\fBsd_bus_close_unref()\fR
and
\fBsd_bus_close_unrefp()\fR
were added in version 241\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-bus\fR(3),
\fBsd_bus_default_user\fR(3),
\fBsd_bus_default_system\fR(3),
\fBsd_bus_open_user\fR(3),
\fBsd_bus_open_system\fR(3),
\fBsd_bus_close\fR(3)
.SH "NOTES"
.IP " 1." 4
Clean-up Variable Attribute
.RS 4
\%https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
.RE
|