]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
0307f791 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> |
cd6d5e1c | 5 | |
7d6b2723 | 6 | <refentry id="sd_bus_new" xmlns:xi="http://www.w3.org/2001/XInclude"> |
cd6d5e1c ZJS |
7 | |
8 | <refentryinfo> | |
9 | <title>sd_bus_new</title> | |
10 | <productname>systemd</productname> | |
cd6d5e1c ZJS |
11 | </refentryinfo> |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>sd_bus_new</refentrytitle> | |
15 | <manvolnum>3</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>sd_bus_new</refname> | |
20 | <refname>sd_bus_ref</refname> | |
21 | <refname>sd_bus_unref</refname> | |
4afd3348 | 22 | <refname>sd_bus_unrefp</refname> |
bd62b744 LP |
23 | <refname>sd_bus_close_unref</refname> |
24 | <refname>sd_bus_close_unrefp</refname> | |
eda0d9a1 LP |
25 | <refname>sd_bus_flush_close_unref</refname> |
26 | <refname>sd_bus_flush_close_unrefp</refname> | |
cd6d5e1c ZJS |
27 | |
28 | <refpurpose>Create a new bus object and create or destroy references to it</refpurpose> | |
29 | </refnamediv> | |
30 | ||
31 | <refsynopsisdiv> | |
32 | <funcsynopsis> | |
33 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
34 | ||
35 | <funcprototype> | |
36 | <funcdef>int <function>sd_bus_new</function></funcdef> | |
8dc385e7 | 37 | <paramdef>sd_bus **<parameter>bus</parameter></paramdef> |
cd6d5e1c ZJS |
38 | </funcprototype> |
39 | ||
40 | <funcprototype> | |
8dc385e7 JE |
41 | <funcdef>sd_bus *<function>sd_bus_ref</function></funcdef> |
42 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
cd6d5e1c ZJS |
43 | </funcprototype> |
44 | ||
45 | <funcprototype> | |
8dc385e7 JE |
46 | <funcdef>sd_bus *<function>sd_bus_unref</function></funcdef> |
47 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
cd6d5e1c | 48 | </funcprototype> |
4afd3348 LP |
49 | |
50 | <funcprototype> | |
bd62b744 LP |
51 | <funcdef>sd_bus *<function>sd_bus_close_unref</function></funcdef> |
52 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
4afd3348 | 53 | </funcprototype> |
eda0d9a1 LP |
54 | |
55 | <funcprototype> | |
56 | <funcdef>sd_bus *<function>sd_bus_flush_close_unref</function></funcdef> | |
57 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
58 | </funcprototype> | |
59 | ||
bd62b744 LP |
60 | <funcprototype> |
61 | <funcdef>void <function>sd_bus_unrefp</function></funcdef> | |
62 | <paramdef>sd_bus **<parameter>busp</parameter></paramdef> | |
63 | </funcprototype> | |
64 | ||
65 | <funcprototype> | |
66 | <funcdef>void <function>sd_bus_close_unrefp</function></funcdef> | |
67 | <paramdef>sd_bus **<parameter>busp</parameter></paramdef> | |
68 | </funcprototype> | |
69 | ||
eda0d9a1 LP |
70 | <funcprototype> |
71 | <funcdef>void <function>sd_bus_flush_close_unrefp</function></funcdef> | |
72 | <paramdef>sd_bus **<parameter>busp</parameter></paramdef> | |
73 | </funcprototype> | |
cd6d5e1c ZJS |
74 | </funcsynopsis> |
75 | </refsynopsisdiv> | |
76 | ||
77 | <refsect1> | |
78 | <title>Description</title> | |
79 | ||
80 | <para><function>sd_bus_new()</function> creates a new bus | |
73e231ab | 81 | object. This object is reference-counted, and will be destroyed |
cd6d5e1c | 82 | when all references are gone. Initially, the caller of this |
db03761e UTL |
83 | function owns the sole reference and the bus object will not be |
84 | connected to any bus. To connect it to a bus, make sure | |
850df10a LP |
85 | to set an address with |
86 | <citerefentry><refentrytitle>sd_bus_set_address</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
87 | or a related call, and then start the connection with | |
88 | <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> | |
89 | ||
27622235 | 90 | <para>In most cases, it is better to use |
850df10a LP |
91 | <citerefentry><refentrytitle>sd_bus_default_user</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
92 | <citerefentry><refentrytitle>sd_bus_default_system</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
27622235 ZJS |
93 | or related calls instead of the more low-level <function>sd_bus_new()</function> and |
94 | <function>sd_bus_start()</function>. The higher-level functions not only allocate a bus object but also | |
95 | start the connection to a well-known bus in a single function call.</para> | |
cd6d5e1c | 96 | |
4afd3348 LP |
97 | <para><function>sd_bus_ref()</function> increases the reference |
98 | counter of <parameter>bus</parameter> by one.</para> | |
cd6d5e1c | 99 | |
4afd3348 LP |
100 | <para><function>sd_bus_unref()</function> decreases the reference |
101 | counter of <parameter>bus</parameter> by one. Once the reference | |
102 | count has dropped to zero, <parameter>bus</parameter> is destroyed | |
103 | and cannot be used anymore, so further calls to | |
104 | <function>sd_bus_ref()</function> or | |
db03761e | 105 | <function>sd_bus_unref()</function> are illegal.</para> |
4afd3348 LP |
106 | |
107 | <para><function>sd_bus_unrefp()</function> is similar to | |
108 | <function>sd_bus_unref()</function> but takes a pointer to a | |
109 | pointer to an <type>sd_bus</type> object. This call is useful in | |
110 | conjunction with GCC's and LLVM's <ulink | |
111 | url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up | |
112 | Variable Attribute</ulink>. Note that this function is defined as | |
113 | inline function. Use a declaration like the following, in order to | |
114 | allocate a bus object that is freed automatically as the code | |
115 | block is left:</para> | |
116 | ||
117 | <programlisting>{ | |
72a68f9d | 118 | __attribute__((cleanup(sd_bus_unrefp))) sd_bus *bus = NULL; |
787f78b6 ZJS |
119 | int r; |
120 | … | |
121 | r = sd_bus_default(&bus); | |
122 | if (r < 0) | |
123 | fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r)); | |
124 | … | |
4afd3348 LP |
125 | }</programlisting> |
126 | ||
2c47fff6 ZJS |
127 | <para><function>sd_bus_ref()</function> and <function>sd_bus_unref()</function> |
128 | execute no operation if the passed in bus object address is | |
129 | <constant>NULL</constant>. <function>sd_bus_unrefp()</function> will first | |
130 | dereference its argument, which must not be <constant>NULL</constant>, and will | |
131 | execute no operation if <emphasis>that</emphasis> is <constant>NULL</constant>. | |
132 | </para> | |
eda0d9a1 | 133 | |
bd62b744 LP |
134 | <para><function>sd_bus_close_unref()</function> is similar to <function>sd_bus_unref()</function>, but |
135 | first executes | |
136 | <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
137 | ensuring that the connection is terminated before the reference to the connection is dropped and possibly | |
138 | the object freed.</para> | |
139 | ||
140 | <para><function>sd_bus_flush_close_unref()</function> is similar to <function>sd_bus_unref()</function>, | |
141 | but first executes | |
142 | <citerefentry><refentrytitle>sd_bus_flush</refentrytitle><manvolnum>3</manvolnum></citerefentry> as well | |
143 | as <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
144 | ensuring that any pending messages are synchronously flushed out before the reference to the connection | |
145 | is dropped and possibly the object freed. This call is particularly useful immediately before exiting | |
146 | from a program as it ensures that any pending outgoing messages are written out, and unprocessed but | |
147 | queued incoming messages released before the connection is terminated and released.</para> | |
148 | ||
149 | <para><function>sd_bus_close_unrefp()</function> is similar to | |
150 | <function>sd_bus_close_unref()</function>, but may be used in GCC's and LLVM's Clean-up Variable | |
151 | Attribute, see above. Similarly, <function>sd_bus_flush_close_unrefp()</function> is similar to | |
152 | <function>sd_bus_flush_close_unref()</function>.</para> | |
cd6d5e1c ZJS |
153 | </refsect1> |
154 | ||
155 | <refsect1> | |
156 | <title>Return Value</title> | |
157 | ||
158 | <para>On success, <function>sd_bus_new()</function> returns 0 or a | |
159 | positive integer. On failure, it returns a negative errno-style | |
160 | error code.</para> | |
161 | ||
4afd3348 | 162 | <para><function>sd_bus_ref()</function> always returns the argument. |
cd6d5e1c ZJS |
163 | </para> |
164 | ||
eda0d9a1 | 165 | <para><function>sd_bus_unref()</function> and <function>sd_bus_flush_close_unref()</function> always return |
cd6d5e1c | 166 | <constant>NULL</constant>.</para> |
cd6d5e1c | 167 | |
b1de39de ZJS |
168 | <refsect2> |
169 | <title>Errors</title> | |
cd6d5e1c | 170 | |
b1de39de | 171 | <para>Returned errors may indicate the following problems:</para> |
cd6d5e1c | 172 | |
b1de39de ZJS |
173 | <variablelist> |
174 | <varlistentry> | |
175 | <term><constant>-ENOMEM</constant></term> | |
cd6d5e1c | 176 | |
b1de39de ZJS |
177 | <listitem><para>Memory allocation failed.</para></listitem> |
178 | </varlistentry> | |
179 | </variablelist> | |
180 | </refsect2> | |
cd6d5e1c ZJS |
181 | </refsect1> |
182 | ||
7d6b2723 | 183 | <xi:include href="libsystemd-pkgconfig.xml" /> |
cd6d5e1c ZJS |
184 | |
185 | <refsect1> | |
186 | <title>See Also</title> | |
187 | ||
188 | <para> | |
189 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
190 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
cd6d5e1c | 191 | <citerefentry><refentrytitle>sd_bus_default_user</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
850df10a LP |
192 | <citerefentry><refentrytitle>sd_bus_default_system</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
193 | <citerefentry><refentrytitle>sd_bus_open_user</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
eda0d9a1 LP |
194 | <citerefentry><refentrytitle>sd_bus_open_system</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
195 | <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
cd6d5e1c ZJS |
196 | </para> |
197 | </refsect1> | |
198 | ||
199 | </refentry> |