1 <?xml version='1.0'?> <!--*-nxml-*-->
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 2013 Lennart Poettering
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_request_name">
27 <title>sd_bus_request_name</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_bus_request_name</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_bus_request_name</refname>
47 <refname>sd_bus_release_name</refname>
48 <refpurpose>Request or release a well-known service name on a bus</refpurpose>
53 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
56 <funcdef>int <function>sd_bus_request_name</function></funcdef>
57 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
58 <paramdef>const char *<parameter>name</parameter></paramdef>
59 <paramdef>uint64_t <parameter>flags</parameter></paramdef>
63 <funcdef>int <function>sd_bus_release_name</function></funcdef>
64 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
65 <paramdef>const char *<parameter>name</parameter></paramdef>
71 <title>Description</title>
73 <para><function>sd_bus_request_name()</function> requests a
74 well-known service name on a bus. It takes a bus connection, a
75 valid bus name and a flags parameter. The flags parameter is a
76 combination of the following flags:</para>
80 <term><varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname></term>
82 <listitem><para>After acquiring the name successfully, permit
83 other peers to take over the name when they try to acquire it
84 with the <varname>SD_BUS_NAME_REPLACE_EXISTING</varname> flag
85 set. If <varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname> is
86 not set on the original request, such a request by other peers
87 will be denied.</para></listitem>
91 <term><varname>SD_BUS_NAME_REPLACE_EXISTING</varname></term>
93 <listitem><para>Take over the name if it is already acquired
94 by another peer, and that other peer has permitted takeover by
95 setting <varname>SD_BUS_NAME_ALLOW_REPLACEMENT</varname> while
96 acquiring it.</para></listitem>
100 <term><varname>SD_BUS_NAME_QUEUE</varname></term>
102 <listitem><para>Queue the acquisition of the name when the
103 name is already taken.</para></listitem>
107 <para><function>sd_bus_release_name()</function> releases an
108 acquired well-known name. It takes a bus connection and a valid
109 bus name as parameters.</para>
113 <title>Return Value</title>
115 <para>On success, these calls return 0 or a positive integer. On
116 failure, these calls return a negative errno-style error
119 <para>If <varname>SD_BUS_NAME_QUEUE</varname> is specified,
120 <function>sd_bus_request_name()</function> will return 0 when the
121 name is already taken by another peer and the client has been
122 added to the queue for the name. In that case, the caller can
123 subscribe to <literal>NameOwnerChanged</literal> signals to be
124 notified when the name is successfully acquired.
125 <function>sd_bus_request_name()</function> returns > 0 when the
126 name has immediately been acquired successfully.</para>
130 <title>Errors</title>
132 <para>Returned errors may indicate the following problems:</para>
136 <term><constant>-EALREADY</constant></term>
138 <listitem><para>The caller already is the owner of the
139 specified name.</para></listitem>
143 <term><constant>-EEXIST</constant></term>
145 <listitem><para>The name has already been acquired by a
146 different peer, and SD_BUS_NAME_REPLACE_EXISTING was not
147 specified or the other peer did not specify
148 SD_BUS_NAME_ALLOW_REPLACEMENT while acquiring the
149 name.</para></listitem>
153 <term><constant>-ESRCH</constant></term>
155 <listitem><para>It was attempted to release a name that is
156 currently not registered on the bus.</para></listitem>
160 <term><constant>-EADDRINUSE</constant></term>
162 <listitem><para>It was attempted to release a name that is
163 owned by a different peer on the bus.</para></listitem>
167 <term><constant>-EINVAL</constant></term>
169 <listitem><para>A specified parameter is invalid. This is also
170 generated when the requested name is a special service name
171 reserved by the D-Bus specification, or when the operation is
172 requested on a connection that does not refer to a
173 bus.</para></listitem>
177 <term><constant>-ENOTCONN</constant></term>
179 <listitem><para>The bus connection has been
180 disconnected.</para></listitem>
184 <term><constant>-ECHILD</constant></term>
186 <listitem><para>The bus connection has been created in a
187 different process than the current one.</para></listitem>
195 <para>The <function>sd_bus_acquire_name()</function> and
196 <function>sd_bus_release_name()</function> interfaces are
197 available as a shared library, which can be compiled and linked to
199 <constant>libelogind</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
204 <title>See Also</title>
207 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>