2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_bus_close"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
10 <title>sd_bus_close</title>
11 <productname>systemd</productname>
15 <refentrytitle>sd_bus_close</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_bus_close</refname>
21 <refname>sd_bus_flush</refname>
22 <refname>sd_bus_default_flush_close</refname>
24 <refpurpose>Close and flush a bus connection</refpurpose>
29 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
32 <funcdef>void <function>sd_bus_close</function></funcdef>
33 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
37 <funcdef>int <function>sd_bus_flush</function></funcdef>
38 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
42 <funcdef>void <function>sd_bus_default_flush_close</function></funcdef>
43 <paramdef>void</paramdef>
49 <title>Description</title>
51 <para><function>sd_bus_close()</function> disconnects the specified bus connection. When this
52 call is invoked and the specified bus object refers to an active connection it is immediately
53 terminated. No further messages may be sent or received on it. Any messages queued in the bus
54 object (both incoming and outgoing) are released. If invoked on <constant>NULL</constant> bus
55 object or when the bus connection is already closed this function executes no operation. This
56 call does not free or unreference the bus object itself. Use
57 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
60 <para><function>sd_bus_flush()</function> synchronously writes out all outgoing queued message
61 on a bus connection if there are any. This function call may block if the peer is not processing
62 bus messages quickly.</para>
64 <para>Before a program exits it is usually a good idea to flush any pending messages with
65 <function>sd_bus_flush()</function> and then close connections with
66 <function>sd_bus_close()</function> to ensure that no unwritten messages are lost, no further
67 messages may be queued and all incoming but unprocessed messages are released. After both
68 operations have been done, it is a good idea to also drop any remaining references to the bus
69 object so that it may be freed. Since these three operations are frequently done together a
71 <citerefentry><refentrytitle>sd_bus_flush_close_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
72 is provided that combines them into one.</para>
74 <para><function>sd_bus_default_flush_close()</function> is similar to
75 <function>sd_bus_flush_close_unref()</function>, but does not take a bus pointer argument and
76 instead iterates over any of the "default" buses opened by
77 <citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
78 <citerefentry><refentrytitle>sd_bus_default_user</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
79 <citerefentry><refentrytitle>sd_bus_default_system</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
80 and similar calls. <function>sd_bus_default_flush_close()</function> is particularly useful to
81 clean up any buses opened using those calls before the program exits.</para>
85 <title>Return Value</title>
87 <para>On success, <function>sd_bus_flush()</function> returns a non-negative integer. On
88 failure, it returns a negative errno-style error code.</para>
93 <para>Returned errors may indicate the following problems:</para>
97 <term><constant>-ECHILD</constant></term>
99 <listitem><para>The bus connection has been created in a different process, library or module instance.</para>
106 <xi:include href="libsystemd-pkgconfig.xml" />
109 <title>History</title>
110 <para><function>sd_bus_close()</function> and
111 <function>sd_bus_flush()</function> were added in version 240.</para>
112 <para><function>sd_bus_default_flush_close()</function> was added in version 246.</para>
116 <title>See Also</title>
119 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
120 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
121 <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
122 <citerefentry><refentrytitle>sd_bus_set_close_on_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>