2018-07-03 00:15:39 +03:00
<?xml version='1.0'?>
2014-01-08 06:46:36 +04:00
< !DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2015-06-18 20:47:44 +03:00
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
2014-01-08 06:46:36 +04:00
<!--
2017-11-18 19:22:32 +03:00
SPDX-License-Identifier: LGPL-2.1+
2014-01-08 06:46:36 +04:00
-->
2018-06-06 12:59:04 +03:00
<refentry id= "sd_bus_error" xmlns:xi= "http://www.w3.org/2001/XInclude" >
2014-01-08 06:46:36 +04:00
<refentryinfo >
<title > sd_bus_error</title>
<productname > systemd</productname>
</refentryinfo>
<refmeta >
<refentrytitle > sd_bus_error</refentrytitle>
<manvolnum > 3</manvolnum>
</refmeta>
<refnamediv >
<refname > sd_bus_error</refname>
2015-06-23 20:37:28 +03:00
<refname > SD_BUS_ERROR_MAKE_CONST</refname>
<refname > SD_BUS_ERROR_NULL</refname>
2014-01-08 06:46:36 +04:00
<refname > sd_bus_error_free</refname>
<refname > sd_bus_error_set</refname>
2015-06-23 20:37:28 +03:00
<refname > sd_bus_error_setf</refname>
2014-01-08 06:46:36 +04:00
<refname > sd_bus_error_set_const</refname>
<refname > sd_bus_error_set_errno</refname>
<refname > sd_bus_error_set_errnof</refname>
2015-06-23 20:37:28 +03:00
<refname > sd_bus_error_set_errnofv</refname>
2014-01-08 06:46:36 +04:00
<refname > sd_bus_error_get_errno</refname>
<refname > sd_bus_error_copy</refname>
2018-08-06 19:54:03 +03:00
<refname > sd_bus_error_move</refname>
2014-01-08 06:46:36 +04:00
<refname > sd_bus_error_is_set</refname>
<refname > sd_bus_error_has_name</refname>
2014-01-13 20:30:51 +04:00
<refpurpose > sd-bus error handling</refpurpose>
2014-01-08 06:46:36 +04:00
</refnamediv>
<refsynopsisdiv >
<funcsynopsis >
<funcsynopsisinfo > #include < systemd/sd-bus.h> </funcsynopsisinfo>
<funcsynopsisinfo > typedef struct {
const char *name;
const char *message;
2016-12-12 01:01:07 +03:00
…
2014-01-08 06:46:36 +04:00
} sd_bus_error;</funcsynopsisinfo>
<para >
<constant > SD_BUS_ERROR_MAKE_CONST(<replaceable > name</replaceable> , <replaceable > message</replaceable> )</constant>
</para>
<para >
<constant > SD_BUS_ERROR_NULL</constant>
</para>
<funcprototype >
2015-06-23 20:37:28 +03:00
<funcdef > void <function > sd_bus_error_free</function> </funcdef>
2014-01-08 06:46:36 +04:00
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_set</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > const char *<parameter > name</parameter> </paramdef>
<paramdef > const char *<parameter > message</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_setf</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > const char *<parameter > name</parameter> </paramdef>
<paramdef > const char *<parameter > format</parameter> </paramdef>
2016-12-12 01:01:07 +03:00
<paramdef > …</paramdef>
2014-01-08 06:46:36 +04:00
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_set_const</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > const char *<parameter > name</parameter> </paramdef>
<paramdef > const char *<parameter > message</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_set_errno</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > int <parameter > error</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_set_errnof</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > int <parameter > error</parameter> </paramdef>
<paramdef > const char *<parameter > format</parameter> </paramdef>
2016-12-12 01:01:07 +03:00
<paramdef > …</paramdef>
2014-01-08 06:46:36 +04:00
</funcprototype>
2015-06-23 20:37:28 +03:00
<funcprototype >
<funcdef > int <function > sd_bus_error_set_errnofv</function> </funcdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > int <parameter > error</parameter> </paramdef>
<paramdef > const char *<parameter > format</parameter> </paramdef>
2018-07-03 00:21:04 +03:00
<paramdef > va_list <parameter > ap</parameter> </paramdef>
2015-06-23 20:37:28 +03:00
</funcprototype>
2014-01-08 06:46:36 +04:00
<funcprototype >
<funcdef > int <function > sd_bus_error_get_errno</function> </funcdef>
<paramdef > const sd_bus_error *<parameter > e</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_copy</function> </funcdef>
<paramdef > sd_bus_error *<parameter > dst</parameter> </paramdef>
<paramdef > const sd_bus_error *<parameter > e</parameter> </paramdef>
</funcprototype>
2018-08-06 19:54:03 +03:00
<funcprototype >
<funcdef > int <function > sd_bus_error_move</function> </funcdef>
<paramdef > sd_bus_error *<parameter > dst</parameter> </paramdef>
<paramdef > sd_bus_error *<parameter > e</parameter> </paramdef>
</funcprototype>
2014-01-08 06:46:36 +04:00
<funcprototype >
<funcdef > int <function > sd_bus_error_is_set</function> </funcdef>
<paramdef > const sd_bus_error *<parameter > e</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_error_has_name</function> </funcdef>
<paramdef > const sd_bus_error *<parameter > e</parameter> </paramdef>
<paramdef > const char *<parameter > name</parameter> </paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 >
<title > Description</title>
2014-02-17 06:37:18 +04:00
<para > The <structname > sd_bus_error</structname> structure carries
2015-06-23 20:37:28 +03:00
information about a D-Bus error condition. The functions described
below may be used to set and query fields in this structure. The
<structfield > name</structfield> field contains a short identifier
of an error. It should follow the rules for error names described
in the D-Bus specification, subsection <ulink
2014-01-08 06:46:36 +04:00
url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
2015-06-23 20:37:28 +03:00
Names</ulink> . A number of common, standardized error names are
described in
<citerefentry > <refentrytitle > sd-bus-errors</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
but additional domain-specific errors may be defined by
applications. The <structfield > message</structfield> field usually
2014-08-03 09:11:12 +04:00
contains a human-readable string describing the details, but might
2015-06-23 20:37:28 +03:00
be NULL. An unset <structname > sd_bus_error</structname> structure
should have both fields initialized to NULL. Set an error
structure to <constant > SD_BUS_ERROR_NULL</constant> in order to
reset both fields to NULL. When no longer necessary, resources
2018-08-06 19:54:51 +03:00
held by the <structname > sd_bus_error</structname> structure should
2015-06-23 20:37:28 +03:00
be destroyed with <function > sd_bus_error_free()</function> .</para>
<para > <function > sd_bus_error_set()</function> sets an error
structure to the specified name and message strings. The strings
will be copied into internal, newly allocated memory. It is
essential to free the error structure again when it is not
required anymore (see above). The function will return an
<varname > errno</varname> -like negative value (see <citerefentry
project='man-pages'><refentrytitle > errno</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> )
determined from the specified error name. Various well-known
D-Bus errors are converted to well-known <varname > errno</varname>
counterparts, and the other ones to <constant > -EIO</constant> . See
<citerefentry > <refentrytitle > sd-bus-errors</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
for a list of well-known error names. Additional error mappings
may be defined with
<citerefentry > <refentrytitle > sd_bus_error_add_map</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> . If
2014-08-03 09:11:12 +04:00
<parameter > e</parameter> is NULL, no error structure is initialized,
2015-06-23 20:37:28 +03:00
but the error is still converted into an
<varname > errno</varname> -style error. If
2014-02-17 06:37:18 +04:00
<parameter > name</parameter> is <constant > NULL</constant> , it is
2014-08-30 19:13:16 +04:00
assumed that no error occurred, and 0 is returned. This means that
2014-01-08 06:46:36 +04:00
this function may be conveniently used in a
2015-06-23 20:37:28 +03:00
<function > return</function> statement. If
2014-08-03 09:11:12 +04:00
<parameter > message</parameter> is NULL, no message is set. This
2015-06-23 20:37:28 +03:00
call can fail if no memory may be allocated for the name and
message strings, in which case an
<constant > SD_BUS_ERROR_NO_MEMORY</constant> error might be set
2014-08-03 09:11:37 +04:00
instead and -ENOMEM be returned. Do not use this call on error
2015-06-23 20:37:28 +03:00
structures that are already initialized. If you intend to reuse an
2014-08-03 09:11:12 +04:00
error structure, free the old data stored in it with
2015-06-23 20:37:28 +03:00
<function > sd_bus_error_free()</function> first.</para>
<para > <function > sd_bus_error_setf()</function> is similar to
<function > sd_bus_error_set()</function> , but takes a <citerefentry
project='man-pages'><refentrytitle > printf</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
format string and corresponding arguments to generate the
<structfield > message</structfield> field.</para>
<para > <function > sd_bus_error_set_const()</function> is similar to
<function > sd_bus_error_set()</function> , but the string parameters
are not copied internally, and must hence remain constant and
valid for the lifetime of <parameter > e</parameter> . Use this call
to avoid memory allocations when setting error structures. Since
2014-08-03 09:11:12 +04:00
this call does not allocate memory, it will not fail with an
out-of-memory condition as
2015-06-23 20:37:28 +03:00
<function > sd_bus_error_set()</function> can, as described
above. Alternatively, the
<constant > SD_BUS_ERROR_MAKE_CONST()</constant> macro may be used
to generate a literal, constant bus error structure
on-the-fly.</para>
<para > <function > sd_bus_error_set_errno()</function> will set
<structfield > name</structfield> from an
<varname > errno</varname> -like value that is converted to a D-Bus
error. <citerefentry
project='die-net'><refentrytitle > strerror_r</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2014-01-08 06:46:36 +04:00
will be used to set <structfield > message</structfield> . Well-known
D-Bus error names will be used for <structfield > name</structfield>
2015-06-23 20:37:28 +03:00
if applicable, otherwise a name in the
<literal > System.Error.</literal> namespace will be generated. The
sign of the specified error number is ignored. The absolute value
is used implicitly. The call always returns a negative value, for
convenient usage in <function > return</function> statements. This
call might fail due to lack of memory, in which case an
<constant > SD_BUS_ERROR_NO_MEMORY</constant> error is set instead,
2014-08-03 09:11:37 +04:00
and -ENOMEM is returned.</para>
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_set_errnof()</function> is similar to
<function > sd_bus_error_set_errno()</function> , but in addition to
<parameter > error</parameter> , takes a <citerefentry
project='man-pages'><refentrytitle > printf</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
format string and corresponding arguments. The
<structfield > message</structfield> field will be generated from
2014-01-08 06:46:36 +04:00
<parameter > format</parameter> and the arguments.</para>
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_set_errnofv()</function> is similar to
2014-08-03 09:11:12 +04:00
<function > sd_bus_error_set_errnof()</function> , but takes the
2015-06-23 20:37:28 +03:00
format string parameters as <citerefentry
project='man-pages'><refentrytitle > va_arg</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
parameter list.</para>
<para > <function > sd_bus_error_get_errno()</function> converts the
<structfield > name</structfield> field of an error structure to an
<varname > errno</varname> -like (positive) value using the same
rules as <function > sd_bus_error_set()</function> . If
2014-01-10 18:10:18 +04:00
<parameter > e</parameter> is <constant > NULL</constant> , 0 will be
returned.</para>
2014-01-08 06:46:36 +04:00
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_copy()</function> will initialize
2014-01-08 06:46:36 +04:00
<parameter > dst</parameter> using the values in
<parameter > e</parameter> . If the strings in
<parameter > e</parameter> were set using
2017-06-30 12:57:13 +03:00
<function > sd_bus_error_set_const()</function> , they will be shared.
2015-06-23 20:37:28 +03:00
Otherwise, they will be copied. Returns a converted
<varname > errno</varname> -like, negative error code.</para>
2014-01-08 06:46:36 +04:00
2018-08-06 19:54:03 +03:00
<para > <function > sd_bus_error_move()</function> is similar to <function > sd_bus_error_copy()</function> , but will
move any error information from <parameter > e</parameter> into <parameter > dst</parameter> , resetting the
former. This function cannot fail, as no new memory is allocated. Note that if <parameter > e</parameter> is not set
(or <constant > NULL</constant> ) <parameter > dst</parameter> is initializated to
<constant > SD_BUS_ERROR_NULL</constant> . Moreover, if <parameter > dst</parameter> is <constant > NULL</constant> no
operation is executed on it and and resources held by <parameter > e</parameter> are freed and reset. Returns a
converted <varname > errno</varname> -like, negative error code.</para>
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_is_set()</function> will return a
non-zero value if <parameter > e</parameter> is
2014-01-08 06:46:36 +04:00
non-<constant > NULL</constant> and an error has been set,
<constant > false</constant> otherwise.</para>
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_has_name()</function> will return a
non-zero value if <parameter > e</parameter> is
non-<constant > NULL</constant> and an error with the same
<parameter > name</parameter> has been set,
2014-01-08 06:46:36 +04:00
<constant > false</constant> otherwise.</para>
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_free()</function> will destroy
resources held by <parameter > e</parameter> . The parameter itself
will not be deallocated, and must be <citerefentry
project='man-pages'><refentrytitle > free</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> d
by the caller if necessary. The function may also be called safely
on unset errors (error structures with both fields set to NULL),
in which case it performs no operation. This call will reset the
error structure after freeing the data, so that all fields are set
to NULL. The structure may be reused afterwards.</para>
2014-01-08 06:46:36 +04:00
</refsect1>
<refsect1 >
<title > Return Value</title>
2015-06-23 20:37:28 +03:00
<para > The functions <function > sd_bus_error_set()</function> ,
2014-08-03 09:11:37 +04:00
<function > sd_bus_error_setf()</function> , and
2015-06-23 20:37:28 +03:00
<function > sd_bus_error_set_const()</function> , when successful,
2014-01-08 06:46:36 +04:00
return the negative errno value corresponding to the
2014-08-03 09:11:37 +04:00
<parameter > name</parameter> parameter. The functions
2015-06-23 20:37:28 +03:00
<function > sd_bus_error_set_errno()</function> ,
<function > sd_bus_error_set_errnof()</function> and
<function > sd_bus_error_set_errnofv()</function> , when successful,
return the negative value of the <parameter > error</parameter>
parameter. If an error occurs, one of the negative error values
listed below will be returned.</para>
<para > <function > sd_bus_error_get_errno()</function> returns
2014-01-08 06:46:36 +04:00
<constant > false</constant> when <parameter > e</parameter> is
<constant > NULL</constant> , and a positive errno value mapped from
2014-02-17 06:58:37 +04:00
<parameter > e-> name</parameter> otherwise.</para>
2014-01-08 06:46:36 +04:00
2018-08-06 19:54:03 +03:00
<para > <function > sd_bus_error_copy()</function> and <function > sd_bus_error_move()</function> return 0 or a positive
integer on success, and a negative error value converted from the error name otherwise.</para>
2014-01-08 06:46:36 +04:00
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_is_set()</function> returns a
non-zero value when <parameter > e</parameter> and the
<structfield > name</structfield> field are
non-<constant > NULL</constant> , zero otherwise.</para>
2014-01-08 06:46:36 +04:00
2015-06-23 20:37:28 +03:00
<para > <function > sd_bus_error_has_name()</function> returns a
non-zero value when <parameter > e</parameter> is
non-<constant > NULL</constant> and the
<structfield > name</structfield> field is equal to
<parameter > name</parameter> , zero otherwise.</para>
2014-01-08 06:46:36 +04:00
</refsect1>
<refsect1 >
<title > Reference ownership</title>
<para > <structname > sd_bus_error</structname> is not reference
counted. Users should destroy resources held by it by calling
2014-08-03 09:11:12 +04:00
<function > sd_bus_error_free()</function> . Usually, error structures
2015-06-23 20:37:28 +03:00
are allocated on the stack or passed in as function parameters,
but they may also be allocated dynamically, in which case it is
the duty of the caller to <citerefentry
project='man-pages'><refentrytitle > free</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
the memory held by the structure itself after freeing its contents
with <function > sd_bus_error_free()</function> .</para>
2014-01-08 06:46:36 +04:00
</refsect1>
<refsect1 >
<title > Errors</title>
<para > Returned errors may indicate the following problems:</para>
<variablelist >
<varlistentry >
2014-09-26 01:27:46 +04:00
<term > <constant > -EINVAL</constant> </term>
2014-01-08 06:46:36 +04:00
<listitem > <para > Error was already set in
<structname > sd_bus_error</structname> structure when one the
error-setting functions was called.</para> </listitem>
</varlistentry>
<varlistentry >
2014-09-26 01:27:46 +04:00
<term > <constant > -ENOMEM</constant> </term>
2014-01-08 06:46:36 +04:00
<listitem > <para > Memory allocation failed.</para> </listitem>
</varlistentry>
</variablelist>
</refsect1>
2018-06-06 12:59:04 +03:00
<xi:include href= "libsystemd-pkgconfig.xml" />
2014-01-08 06:46:36 +04:00
<refsect1 >
<title > See Also</title>
<para >
<citerefentry > <refentrytitle > systemd</refentrytitle> <manvolnum > 1</manvolnum> </citerefentry> ,
<citerefentry > <refentrytitle > sd-bus</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
2015-06-23 20:37:28 +03:00
<citerefentry > <refentrytitle > sd-bus-errors</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
<citerefentry > <refentrytitle > sd_bus_error_add_map</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
man: add a mapping for external manpages
It is annoying when we have dead links on fd.o.
Add project='man-pages|die-net|archlinux' to <citerefentry>-ies.
In generated html, add external links to
http://man7.org/linux/man-pages/man, http://linux.die.net/man/,
https://www.archlinux.org/.
By default, pages in sections 2 and 4 go to man7, since Michael
Kerrisk is the autorative source on kernel related stuff.
The rest of links goes to linux.die.net, because they have the
manpages.
Except for the pacman stuff, since it seems to be only available from
archlinux.org.
Poor gummiboot gets no link, because gummitboot(8) ain't to be found
on the net. According to common wisdom, that would mean that it does
not exist. But I have seen Kay using it, so I know it does, and
deserves to be found. Can somebody be nice and put it up somewhere?
2014-07-08 02:25:54 +04:00
<citerefentry project= 'man-pages' > <refentrytitle > errno</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
2015-06-23 20:37:28 +03:00
<citerefentry project= 'die-net' > <refentrytitle > strerror_r</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2014-01-08 06:46:36 +04:00
</para>
</refsect1>
</refentry>