1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id=
"sd_bus_open_user" conditional=
"ENABLE_KDBUS">
27 <title>sd_bus_open_user
</title>
28 <productname>systemd
</productname>
32 <contrib>A monkey with a typewriter
</contrib>
33 <firstname>Zbigniew
</firstname>
34 <surname>Jędrzejewski-Szmek
</surname>
35 <email>zbyszek@in.waw.pl
</email>
41 <refentrytitle>sd_bus_open_user
</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_bus_open_user
</refname>
47 <refname>sd_bus_open_system
</refname>
48 <refname>sd_bus_open_system_remote
</refname>
49 <refname>sd_bus_open_system_container
</refname>
51 <refname>sd_bus_default_user
</refname>
52 <refname>sd_bus_default_system
</refname>
54 <refpurpose>Open a connection to the system or user bus
</refpurpose>
59 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
62 <funcdef>int
<function>sd_bus_open_user
</function></funcdef>
63 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
67 <funcdef>int
<function>sd_bus_open_system
</function></funcdef>
68 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
72 <funcdef>int
<function>sd_bus_open_system_remote
</function></funcdef>
73 <paramdef>const char *
<parameter>host
</parameter></paramdef>
74 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
78 <funcdef>int
<function>sd_bus_open_system_container
</function></funcdef>
79 <paramdef>const char *
<parameter>machine
</parameter></paramdef>
80 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
84 <funcdef>int
<function>sd_bus_default_user
</function></funcdef>
85 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
89 <funcdef>int
<function>sd_bus_default_system
</function></funcdef>
90 <paramdef>sd_bus **
<parameter>bus
</parameter></paramdef>
96 <title>Description
</title>
98 <para><function>sd_bus_open_user()
</function> creates a new bus
99 object and opens a connection to the user bus.
100 <function>sd_bus_open_system()
</function> does the same, but
101 connects to the system bus.
</para>
103 <para>If the
<varname>$DBUS_SESSION_BUS_ADDRESS
</varname> environment
105 (cf.
<citerefentry project='man-pages'
><refentrytitle>environ
</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
106 it will be used as the address of the user bus. This variable can
107 contain multiple addresses separated by
<literal>;
</literal>. If
108 this variable is not set, a suitable default for the default user
109 D-Bus instance will be used.
</para>
111 <para>If the
<varname>$DBUS_SYSTEM_BUS_ADDRESS
</varname> environment
112 variable is set, it will be used as the address of the system
113 bus. This variable uses the same syntax as
114 <varname>$DBUS_SESSION_BUS_ADDRESS
</varname>/. If this variable is
115 not set, a suitable default for the default system D-Bus instance
118 <para><function>sd_bus_open_system_remote()
</function> connects to
119 the system bus on the specified
<parameter>host
</parameter> using
120 SSH.
<parameter>host
</parameter> consists of an optional user name
121 followed by the
<literal>@
</literal> symbol, and the hostname.
124 <para><function>sd_bus_open_system_container()
</function> connects
125 to the system bus in the specified
<parameter>machine
</parameter>,
126 where
<parameter>machine
</parameter> is the name of a container.
128 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
129 for more information about
"machines".
</para>
131 <para><function>sd_bus_default_user()
</function> returns a bus
132 object connected to the user bus. Each thread has its own object, but it
133 may be passed around. It is created on the first invocation of
134 <function>sd_bus_default_user()
</function>, and subsequent
135 invocations returns a reference to the same object.
</para>
137 <para><function>sd_bus_default_system()
</function> is similar to
138 <function>sd_bus_default_user()
</function>, but connects to the
143 <title>Return Value
</title>
145 <para>On success, these calls return
0 or a positive
146 integer. On failure, these calls return a negative
147 errno-style error code.
</para>
151 <title>Reference ownership
</title>
152 <para>Functions
<function>sd_bus_open_user()
</function>,
153 <function>sd_bus_open_system()
</function>,
154 <function>sd_bus_open_system_remote()
</function>, and
155 <function>sd_bus_open_system_machine()
</function> return a new
156 object and the caller owns the sole reference. When not needed
157 anymore, this reference should be destroyed with
158 <citerefentry><refentrytitle>sd_bus_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
161 <para>The functions
<function>sd_bus_default_user()
</function> and
162 <function>sd_bus_default_system()
</function> do not create a new
167 <title>Errors
</title>
169 <para>Returned errors may indicate the following problems:
</para>
174 <term><constant>-EINVAL
</constant></term>
176 <listitem><para>Specified parameter is invalid
177 (
<constant>NULL
</constant> in case of output
178 parameters).
</para></listitem>
182 <term><constant>-ENOMEM
</constant></term>
184 <listitem><para>Memory allocation failed.
</para></listitem>
187 <para>In addition, any further connection-related errors may be
188 by returned. See
<citerefentry><refentrytitle>sd_bus_send
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
195 <para><function>sd_bus_open_user()
</function> and other functions
196 described here are available as a shared library, which can be
197 compiled and linked to with the
198 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
203 <title>See Also
</title>
206 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
207 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd_bus_new
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_bus_ref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
210 <citerefentry><refentrytitle>sd_bus_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
211 <citerefentry><refentrytitle>ssh
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
212 <citerefentry><refentrytitle>systemd-machined.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
213 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>