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" [
4 <!ENTITY % entities SYSTEM
"custom-entities.ent" >
9 This file is part of systemd.
11 Copyright 2014 Zbigniew Jędrzejewski-Szmek
13 systemd is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
18 systemd is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public License
24 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 <refentry id=
"sd_bus_error">
30 <title>sd_bus_error
</title>
31 <productname>systemd
</productname>
35 <contrib>A monkey with a typewriter
</contrib>
36 <firstname>Zbigniew
</firstname>
37 <surname>Jędrzejewski-Szmek
</surname>
38 <email>zbyszek@in.waw.pl
</email>
44 <refentrytitle>sd_bus_error
</refentrytitle>
45 <manvolnum>3</manvolnum>
49 <refname>sd_bus_error
</refname>
50 <refname>sd_bus_error_free
</refname>
51 <refname>sd_bus_error_set
</refname>
52 <refname>sd_bus_error_set_const
</refname>
53 <refname>sd_bus_error_set_errno
</refname>
54 <refname>sd_bus_error_set_errnof
</refname>
55 <refname>sd_bus_error_get_errno
</refname>
56 <refname>sd_bus_error_copy
</refname>
57 <refname>sd_bus_error_is_set
</refname>
58 <refname>sd_bus_error_has_name
</refname>
60 <refpurpose>sd-bus error handling
</refpurpose>
65 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
67 <funcsynopsisinfo>typedef struct {
71 } sd_bus_error;
</funcsynopsisinfo>
74 <constant>SD_BUS_ERROR_MAKE_CONST(
<replaceable>name
</replaceable>,
<replaceable>message
</replaceable>)
</constant>
77 <constant>SD_BUS_ERROR_NULL
</constant>
81 <funcdef>int
<function>sd_bus_error_free
</function></funcdef>
82 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
86 <funcdef>int
<function>sd_bus_error_set
</function></funcdef>
87 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
88 <paramdef>const char *
<parameter>name
</parameter></paramdef>
89 <paramdef>const char *
<parameter>message
</parameter></paramdef>
93 <funcdef>int
<function>sd_bus_error_setf
</function></funcdef>
94 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
95 <paramdef>const char *
<parameter>name
</parameter></paramdef>
96 <paramdef>const char *
<parameter>format
</parameter></paramdef>
97 <paramdef>...
</paramdef>
101 <funcdef>int
<function>sd_bus_error_set_const
</function></funcdef>
102 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
103 <paramdef>const char *
<parameter>name
</parameter></paramdef>
104 <paramdef>const char *
<parameter>message
</parameter></paramdef>
108 <funcdef>int
<function>sd_bus_error_set_errno
</function></funcdef>
109 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
110 <paramdef>int
<parameter>error
</parameter></paramdef>
114 <funcdef>int
<function>sd_bus_error_set_errnof
</function></funcdef>
115 <paramdef>sd_bus_error *
<parameter>e
</parameter></paramdef>
116 <paramdef>int
<parameter>error
</parameter></paramdef>
117 <paramdef>const char *
<parameter>format
</parameter></paramdef>
118 <paramdef>...
</paramdef>
122 <funcdef>int
<function>sd_bus_error_get_errno
</function></funcdef>
123 <paramdef>const sd_bus_error *
<parameter>e
</parameter></paramdef>
127 <funcdef>int
<function>sd_bus_error_copy
</function></funcdef>
128 <paramdef>sd_bus_error *
<parameter>dst
</parameter></paramdef>
129 <paramdef>const sd_bus_error *
<parameter>e
</parameter></paramdef>
133 <funcdef>int
<function>sd_bus_error_is_set
</function></funcdef>
134 <paramdef>const sd_bus_error *
<parameter>e
</parameter></paramdef>
138 <funcdef>int
<function>sd_bus_error_has_name
</function></funcdef>
139 <paramdef>const sd_bus_error *
<parameter>e
</parameter></paramdef>
140 <paramdef>const char *
<parameter>name
</parameter></paramdef>
145 <constant>SD_BUS_ERROR_FAILED
</constant>
148 <constant>SD_BUS_ERROR_NO_MEMORY
</constant>
151 <constant>SD_BUS_ERROR_SERVICE_UNKNOWN
</constant>
154 <constant>SD_BUS_ERROR_NAME_HAS_NO_OWNER
</constant>
157 <constant>SD_BUS_ERROR_NO_REPLY
</constant>
160 <constant>SD_BUS_ERROR_IO_ERROR
</constant>
163 <constant>SD_BUS_ERROR_BAD_ADDRESS
</constant>
166 <constant>SD_BUS_ERROR_NOT_SUPPORTED
</constant>
169 <constant>SD_BUS_ERROR_LIMITS_EXCEEDED
</constant>
172 <constant>SD_BUS_ERROR_ACCESS_DENIED
</constant>
175 <constant>SD_BUS_ERROR_AUTH_FAILED
</constant>
178 <constant>SD_BUS_ERROR_NO_SERVER
</constant>
181 <constant>SD_BUS_ERROR_TIMEOUT
</constant>
184 <constant>SD_BUS_ERROR_NO_NETWORK
</constant>
187 <constant>SD_BUS_ERROR_ADDRESS_IN_USE
</constant>
190 <constant>SD_BUS_ERROR_DISCONNECTED
</constant>
193 <constant>SD_BUS_ERROR_INVALID_ARGS
</constant>
196 <constant>SD_BUS_ERROR_FILE_NOT_FOUND
</constant>
199 <constant>SD_BUS_ERROR_FILE_EXISTS
</constant>
202 <constant>SD_BUS_ERROR_UNKNOWN_METHOD
</constant>
205 <constant>SD_BUS_ERROR_UNKNOWN_OBJECT
</constant>
208 <constant>SD_BUS_ERROR_UNKNOWN_INTERFACE
</constant>
211 <constant>SD_BUS_ERROR_UNKNOWN_PROPERTY
</constant>
214 <constant>SD_BUS_ERROR_PROPERTY_READ_ONLY
</constant>
217 <constant>SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN
</constant>
220 <constant>SD_BUS_ERROR_INVALID_SIGNATURE
</constant>
223 <constant>SD_BUS_ERROR_INCONSISTENT_MESSAGE
</constant>
226 <constant>SD_BUS_ERROR_MATCH_RULE_NOT_FOUND
</constant>
229 <constant>SD_BUS_ERROR_MATCH_RULE_INVALID
</constant>
235 <title>Description
</title>
237 <para>The
<structname>sd_bus_error
</structname> structure carries
238 information for a
<filename>sd-bus
</filename> error. The
239 functions described below can be used to set and query fields in
240 this structure. The
<structfield>name
</structfield> field contains a
241 short identifier of an error. It should follow the rules for error
242 names described in the D-Bus specification, subsection
<ulink
243 url=
"http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
244 Names
</ulink>. The
<structfield>message
</structfield> is a human
245 readable string describing the details. When no longer necessary,
246 resources held by this structure should be destroyed with
247 <function>sd_bus_error_free
</function>.
</para>
249 <para><function>sd_bus_error_set
</function> will return an
250 errno-like negative value returned based on parameter
251 <parameter>name
</parameter> (see
252 <citerefentry project='man-pages'
><refentrytitle>errno
</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
253 Various well-known D-Bus errors are converted to specific values,
254 and the remaining ones to
<constant>-ENXIO
</constant>. Well-known
255 D-Bus error names are available as constants
256 <constant>SD_BUS_ERROR_FAILED
</constant>, etc., listed above. If
257 <parameter>name
</parameter> is
<constant>NULL
</constant>, it is
258 assumed that no error occurred, and
0 is returned. This means that
259 this function may be conveniently used in a
260 <function>return
</function> statement.
</para>
262 <para>If
<parameter>e
</parameter> is not
263 <constant>NULL
</constant>,
<structfield>name
</structfield> and
264 <structfield>message
</structfield> in the
265 <structname>sd_bus_error
</structname> structure
266 <parameter>e
</parameter> points at will be filled in. As described above,
267 <parameter>name
</parameter> may be
<constant>NULL
</constant>,
268 which is treated as no error. Parameter
269 <parameter>message
</parameter> may also be
270 <constant>NULL
</constant>, in which case no message is specified.
271 <function>sd_bus_error_set
</function> will make internal copies of
272 specified strings.
</para>
274 <para><function>sd_bus_error_setf
</function> is similar to
275 <function>sd_bus_error_set
</function>, but takes a
276 <citerefentry project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
277 format string and corresponding arguments to generate
278 <structname>message
</structname>.
</para>
280 <para><function>sd_bus_error_set_const
</function> is similar to
281 <function>sd_bus_error_set
</function>, but string parameters are
282 not copied internally, and must remain valid for the lifetime of
283 <parameter>e
</parameter>.
</para>
285 <para><function>sd_bus_error_set_errno
</function> will set
286 <structfield>name
</structfield> based on an errno-like value.
287 <citerefentry project='die-net'
><refentrytitle>strerror
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
288 will be used to set
<structfield>message
</structfield>. Well-known
289 D-Bus error names will be used for
<structfield>name
</structfield>
290 if available, otherwise a name in the
291 <literal>System.Error
</literal> namespace will be generated.
294 <para><function>sd_bus_error_set_errnof
</function> is similar to
295 <function>sd_bus_error_set_errno
</function>, but in addition to
296 <parameter>name
</parameter>, takes a
297 <citerefentry project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
298 format and corresponding arguments.
299 <structfield>name
</structfield> will be generated from
300 <parameter>format
</parameter> and the arguments.
</para>
302 <para><function>sd_bus_error_get_errno
</function> will convert
303 <structname>e-
>name
</structname> to an errno-like value using the
304 same rules as
<function>sd_bus_error_set
</function>. If
305 <parameter>e
</parameter> is
<constant>NULL
</constant>,
0 will be
308 <para><function>sd_bus_error_copy
</function> will initialize
309 <parameter>dst
</parameter> using the values in
310 <parameter>e
</parameter>. If the strings in
311 <parameter>e
</parameter> were set using
312 <function>sd_bus_set_error_const
</function>, they will be shared.
313 Otherwise, they will be copied.
</para>
315 <para><function>sd_bus_error_is_set
</function> will return
316 <constant>true
</constant> if
<parameter>e
</parameter> is
317 non-
<constant>NULL
</constant> and an error has been set,
318 <constant>false
</constant> otherwise.
</para>
320 <para><function>sd_bus_error_has_name
</function> will return true
321 if
<parameter>e
</parameter> is non-
<constant>NULL
</constant> and
322 an error with the same
<parameter>name
</parameter> has been set,
323 <constant>false
</constant> otherwise.
</para>
325 <para><function>sd_bus_error_free
</function> will destroy resources
326 held by
<parameter>e
</parameter>. The parameter itself will not
327 be deallocated, and must be
328 <citerefentry project='man-pages'
><refentrytitle>free
</refentrytitle><manvolnum>3</manvolnum></citerefentry>d
329 by the caller if necessary.
</para>
333 <title>Return Value
</title>
335 <para>Functions
<function>sd_bus_error_set
</function>,
336 <function>sd_bus_error_setf
</function>,
337 <function>sd_bus_error_set_const
</function>, when successful,
338 return the negative errno value corresponding to the
339 <parameter>name
</parameter> parameter. Functions
340 <function>sd_bus_error_set_errno
</function> and
341 <function>sd_bus_error_set_errnof
</function>, when successful,
342 return the value of the
<parameter>errno
</parameter> parameter. If
343 an error occurs, one of the negative error values listed below
344 will be returned.
</para>
346 <para><function>sd_bus_error_get_errno
</function> returns
347 <constant>false
</constant> when
<parameter>e
</parameter> is
348 <constant>NULL
</constant>, and a positive errno value mapped from
349 <parameter>e-
>name
</parameter> otherwise.
</para>
351 <para><function>sd_bus_error_copy
</function> returns
0 or a
352 positive integer on success, and one of the negative error values
353 listed below otherwise.
</para>
355 <para><function>sd_bus_error_is_set
</function> returns
356 <constant>true
</constant> when
<parameter>e
</parameter> and
357 <parameter>e-
>name
</parameter> are non-
<constant>NULL
</constant>,
358 <constant>false
</constant> otherwise.
</para>
360 <para><function>sd_bus_error_has_name
</function> returns
361 <constant>true
</constant> when
<parameter>e
</parameter> is
362 non-
<constant>NULL
</constant> and
<parameter>e-
>name
</parameter>
363 is equal to
<parameter>name
</parameter>,
364 <constant>false
</constant> otherwise.
</para>
368 <title>Reference ownership
</title>
369 <para><structname>sd_bus_error
</structname> is not reference
370 counted. Users should destroy resources held by it by calling
371 <function>sd_bus_error_free
</function>.
</para>
375 <title>Errors
</title>
377 <para>Returned errors may indicate the following problems:
</para>
382 <term><constant>-EINVAL
</constant></term>
384 <listitem><para>Error was already set in
385 <structname>sd_bus_error
</structname> structure when one the
386 error-setting functions was called.
</para></listitem>
390 <term><constant>-ENOMEM
</constant></term>
392 <listitem><para>Memory allocation failed.
</para></listitem>
400 <para><function>sd_bus_set_error()
</function> and other functions
401 described here are available as a shared library, which can be
402 compiled and linked to with the
403 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
408 <title>See Also
</title>
411 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
412 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
413 <citerefentry project='man-pages'
><refentrytitle>errno
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
414 <citerefentry project='die-net'
><refentrytitle>strerror
</refentrytitle><manvolnum>3</manvolnum></citerefentry>