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