2018-07-03 05:15:39 +08:00
|
|
|
<?xml version='1.0'?>
|
2019-03-14 21:40:58 +08:00
|
|
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
|
|
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
2020-11-09 12:23:58 +08:00
|
|
|
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2018-06-06 17:59:04 +08:00
|
|
|
<refentry id="sd_bus_error" xmlns:xi="http://www.w3.org/2001/XInclude">
|
2014-01-08 10:46:36 +08: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-24 01:37:28 +08:00
|
|
|
<refname>SD_BUS_ERROR_MAKE_CONST</refname>
|
|
|
|
<refname>SD_BUS_ERROR_NULL</refname>
|
2014-01-08 10:46:36 +08:00
|
|
|
<refname>sd_bus_error_free</refname>
|
|
|
|
<refname>sd_bus_error_set</refname>
|
2015-06-24 01:37:28 +08:00
|
|
|
<refname>sd_bus_error_setf</refname>
|
2022-06-13 16:11:22 +08:00
|
|
|
<refname>sd_bus_error_setfv</refname>
|
2014-01-08 10:46:36 +08:00
|
|
|
<refname>sd_bus_error_set_const</refname>
|
|
|
|
<refname>sd_bus_error_set_errno</refname>
|
|
|
|
<refname>sd_bus_error_set_errnof</refname>
|
2015-06-24 01:37:28 +08:00
|
|
|
<refname>sd_bus_error_set_errnofv</refname>
|
2014-01-08 10:46:36 +08:00
|
|
|
<refname>sd_bus_error_get_errno</refname>
|
|
|
|
<refname>sd_bus_error_copy</refname>
|
2018-08-07 00:54:03 +08:00
|
|
|
<refname>sd_bus_error_move</refname>
|
2014-01-08 10:46:36 +08:00
|
|
|
<refname>sd_bus_error_is_set</refname>
|
|
|
|
<refname>sd_bus_error_has_name</refname>
|
2020-08-23 00:24:43 +08:00
|
|
|
<refname>sd_bus_error_has_names_sentinel</refname>
|
|
|
|
<refname>sd_bus_error_has_names</refname>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2014-01-14 00:30:51 +08:00
|
|
|
<refpurpose>sd-bus error handling</refpurpose>
|
2014-01-08 10:46:36 +08:00
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<funcsynopsis>
|
|
|
|
<funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
|
|
|
|
|
|
|
|
<funcsynopsisinfo>typedef struct {
|
|
|
|
const char *name;
|
|
|
|
const char *message;
|
2016-12-12 06:01:07 +08:00
|
|
|
…
|
2014-01-08 10:46:36 +08: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-24 01:37:28 +08:00
|
|
|
<funcdef>void <function>sd_bus_error_free</function></funcdef>
|
2014-01-08 10:46:36 +08: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 06:01:07 +08:00
|
|
|
<paramdef>…</paramdef>
|
2014-01-08 10:46:36 +08:00
|
|
|
</funcprototype>
|
|
|
|
|
2022-06-13 16:11:22 +08:00
|
|
|
<funcprototype>
|
|
|
|
<funcdef>int <function>sd_bus_error_setfv</function></funcdef>
|
|
|
|
<paramdef>sd_bus_error *<parameter>e</parameter></paramdef>
|
|
|
|
<paramdef>const char *<parameter>name</parameter></paramdef>
|
|
|
|
<paramdef>const char *<parameter>format</parameter></paramdef>
|
|
|
|
<paramdef>va_list <parameter>ap</parameter></paramdef>
|
|
|
|
</funcprototype>
|
|
|
|
|
2014-01-08 10:46:36 +08:00
|
|
|
<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 06:01:07 +08:00
|
|
|
<paramdef>…</paramdef>
|
2014-01-08 10:46:36 +08:00
|
|
|
</funcprototype>
|
|
|
|
|
2015-06-24 01:37:28 +08: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 05:21:04 +08:00
|
|
|
<paramdef>va_list <parameter>ap</parameter></paramdef>
|
2015-06-24 01:37:28 +08:00
|
|
|
</funcprototype>
|
|
|
|
|
2014-01-08 10:46:36 +08: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-07 00:54:03 +08: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 10:46:36 +08: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>
|
2020-08-23 00:24:43 +08:00
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
<funcdef>int <function>sd_bus_error_has_names_sentinel</function></funcdef>
|
|
|
|
<paramdef>const sd_bus_error *<parameter>e</parameter></paramdef>
|
|
|
|
<paramdef>...</paramdef>
|
|
|
|
</funcprototype>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
#define sd_bus_error_has_names(e, ...) sd_bus_error_has_names_sentinel(e, ..., NULL)
|
|
|
|
</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
</funcsynopsis>
|
|
|
|
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
2021-03-31 17:46:31 +08:00
|
|
|
<para>The <structname>sd_bus_error</structname> structure carries information about a D-Bus error
|
|
|
|
condition, or lack thereof. The functions described below may be used to set and query fields in this
|
|
|
|
structure.
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>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
|
2022-06-28 18:00:47 +08:00
|
|
|
url="https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
|
2021-03-31 17:46:31 +08: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.</para></listitem>
|
|
|
|
|
|
|
|
<listitem><para>The <structfield>message</structfield> field usually contains a human-readable string
|
|
|
|
describing the details, but might be <constant>NULL</constant>.</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
An unset <structname>sd_bus_error</structname> structure should have both fields initialized to
|
|
|
|
<constant>NULL</constant>, and signifies lack of an error, i.e. success. Assign
|
|
|
|
<constant>SD_BUS_ERROR_NULL</constant> to the structure in order to initialize both fields to
|
|
|
|
<constant>NULL</constant>. When no longer necessary, resources held by the
|
|
|
|
<structname>sd_bus_error</structname> structure should 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
|
|
|
|
contents again when they are not required anymore (see above). Do not use this call on error structures
|
|
|
|
that have already been set. If you intend to reuse an error structure, free the old data stored in it
|
|
|
|
with <function>sd_bus_error_free()</function> first.</para>
|
|
|
|
|
|
|
|
<para><function>sd_bus_error_set()</function> will return an <varname>errno</varname>-like value (see
|
|
|
|
<citerefentry
|
2015-06-24 01:37:28 +08:00
|
|
|
project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>)
|
2021-03-31 17:46:31 +08:00
|
|
|
determined from the specified error name <parameter>name</parameter>. If <parameter>name</parameter> is
|
|
|
|
<constant>NULL</constant>, it is assumed that no error occurred, and <constant>0</constant> is returned.
|
|
|
|
If <parameter>name</parameter> is nonnull, a negative value is always returned. If
|
|
|
|
<parameter>e</parameter> is <constant>NULL</constant>, no error structure is initialized, but
|
|
|
|
<parameter>name</parameter> is still converted into an <varname>errno</varname>-style value.</para>
|
|
|
|
|
|
|
|
<para>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>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para><function>sd_bus_error_set()</function> is designed to be conveniently used in a
|
|
|
|
<function>return</function> statement. If <parameter>message</parameter> is <constant>NULL</constant>, no
|
|
|
|
message is set. This 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 will be set instead and
|
|
|
|
<constant>-ENOMEM</constant> returned. </para>
|
2015-06-24 01:37:28 +08:00
|
|
|
|
2022-06-13 16:11:22 +08:00
|
|
|
<para><function>sd_bus_error_setf()</function> and <function>sd_bus_error_setfv()</function> are similar
|
|
|
|
to <function>sd_bus_error_set()</function>, but take a <citerefentry
|
|
|
|
project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry> format
|
|
|
|
string and corresponding arguments to generate the <structfield>message</structfield> field.
|
|
|
|
<function>sd_bus_error_setf()</function> uses variadic arguments, and
|
|
|
|
<function>sd_bus_error_setfv()</function> accepts the arguments as a
|
|
|
|
<citerefentry
|
|
|
|
project='man-pages'><refentrytitle>va_arg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
parameter list.</para>
|
2015-06-24 01:37:28 +08:00
|
|
|
|
|
|
|
<para><function>sd_bus_error_set_const()</function> is similar to
|
2021-03-31 17:46:31 +08:00
|
|
|
<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 this call does not allocate memory, it will not
|
|
|
|
fail with an out-of-memory condition as <function>sd_bus_error_set()</function> may, 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 immediately return <constant>0</constant> if the
|
|
|
|
specified error parameter <parameter>error</parameter> is <constant>0</constant>. Otherwise, it will set
|
|
|
|
<structfield>name</structfield> from an <varname>errno</varname>-like value that is converted to a D-Bus
|
2015-06-24 01:37:28 +08:00
|
|
|
error. <citerefentry
|
2021-03-31 17:46:31 +08:00
|
|
|
project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry> will
|
|
|
|
be used to set <structfield>message</structfield>. Well-known D-Bus error names will be used for
|
|
|
|
<structfield>name</structfield> if applicable, otherwise a name in the <literal>System.Error.</literal>
|
|
|
|
namespace will be generated. The sign of the specified error number is ignored and the absolute value is
|
|
|
|
used implicitly. If the specified error <parameter>error</parameter> is non-zero, 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,
|
|
|
|
and <constant>-ENOMEM</constant> is returned.</para>
|
2015-06-24 01:37:28 +08:00
|
|
|
|
2022-06-13 16:11:22 +08:00
|
|
|
<para><function>sd_bus_error_set_errnof()</function> and <function>sd_bus_error_set_errnof()</function>
|
|
|
|
are similar to <function>sd_bus_error_set_errno()</function>, but in addition to
|
|
|
|
<parameter>error</parameter>, take 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
|
|
|
|
<parameter>format</parameter> and the arguments.
|
|
|
|
<function>sd_bus_error_set_errnof()</function> uses variadic arguments, and
|
|
|
|
<function>sd_bus_error_set_errnofv()</function> accepts the arguments as a
|
|
|
|
<citerefentry
|
2015-06-24 01:37:28 +08:00
|
|
|
project='man-pages'><refentrytitle>va_arg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
parameter list.</para>
|
|
|
|
|
2021-03-31 17:46:31 +08:00
|
|
|
<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 <parameter>e</parameter> is <constant>NULL</constant>,
|
|
|
|
<constant>0</constant> will be returned.</para>
|
|
|
|
|
|
|
|
<para><function>sd_bus_error_copy()</function> will initialize <parameter>dst</parameter> using the
|
|
|
|
values in <parameter>e</parameter>, if <parameter>e</parameter> has been set with an error value before.
|
|
|
|
Otherwise, it will return immediately. If the strings in <parameter>e</parameter> were set using
|
|
|
|
<function>sd_bus_error_set_const()</function>, they will be shared. Otherwise, they will be
|
2022-05-26 20:04:52 +08:00
|
|
|
copied. Before this call, <parameter>dst</parameter> must be unset, i.e. either freshly initialized with
|
2021-03-31 17:46:31 +08:00
|
|
|
<constant>NULL</constant> or reset using <function>sd_bus_error_free()</function>.</para>
|
|
|
|
|
2022-05-26 20:04:52 +08:00
|
|
|
<para><function>sd_bus_error_copy()</function> generally returns <constant>0</constant> or a negative
|
|
|
|
<varname>errno</varname>-like value based on the input parameter <parameter>e</parameter>:
|
|
|
|
<constant>0</constant> if it was unset and a negative integer if it was set to some error, similarly to
|
|
|
|
<function>sd_bus_error_set()</function>. It may however also return an error generated internally, for
|
|
|
|
example <constant>-ENOMEM</constant> if a memory allocation fails.</para>
|
|
|
|
|
2021-03-31 17:46:31 +08: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
|
2021-06-15 13:19:30 +08:00
|
|
|
<parameter>e</parameter> is not set, <parameter>dst</parameter> is initialized to
|
2021-03-31 17:46:31 +08:00
|
|
|
<constant>SD_BUS_ERROR_NULL</constant>. Moreover, if <parameter>dst</parameter> is
|
|
|
|
<constant>NULL</constant> no operation is executed on it and resources held by <parameter>e</parameter>
|
|
|
|
are freed and reset. Returns a converted <varname>errno</varname>-like, non-positive error value.</para>
|
2018-08-07 00:54:03 +08:00
|
|
|
|
2015-06-24 01:37:28 +08:00
|
|
|
<para><function>sd_bus_error_is_set()</function> will return a
|
|
|
|
non-zero value if <parameter>e</parameter> is
|
2014-01-08 10:46:36 +08:00
|
|
|
non-<constant>NULL</constant> and an error has been set,
|
|
|
|
<constant>false</constant> otherwise.</para>
|
|
|
|
|
2015-06-24 01:37:28 +08: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 10:46:36 +08:00
|
|
|
<constant>false</constant> otherwise.</para>
|
|
|
|
|
2020-08-23 00:24:43 +08:00
|
|
|
<para><function>sd_bus_error_has_names_sentinel()</function> is similar to
|
|
|
|
<function>sd_bus_error_has_name()</function>, but takes multiple names to check against. The list must be
|
|
|
|
terminated with <constant>NULL</constant>. <function>sd_bus_error_has_names()</function>
|
|
|
|
is a macro wrapper around <function>sd_bus_error_has_names_sentinel()</function> that adds the
|
|
|
|
<constant>NULL</constant> sentinel automatically.</para>
|
|
|
|
|
2015-06-24 01:37:28 +08: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
|
2020-11-12 15:58:00 +08:00
|
|
|
on unset errors (error structures with both fields set to <constant>NULL</constant>),
|
2015-06-24 01:37:28 +08:00
|
|
|
in which case it performs no operation. This call will reset the
|
|
|
|
error structure after freeing the data, so that all fields are set
|
2020-11-12 15:58:00 +08:00
|
|
|
to <constant>NULL</constant>. The structure may be reused afterwards.</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
</refsect1>
|
|
|
|
|
2022-05-26 20:04:52 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>Reference ownership</title>
|
|
|
|
|
|
|
|
<para><structname>sd_bus_error</structname> is not reference-counted. Users should destroy resources held
|
|
|
|
by it by calling <function>sd_bus_error_free()</function>. Usually, error structures 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>
|
|
|
|
</refsect1>
|
|
|
|
|
2014-01-08 10:46:36 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>Return Value</title>
|
|
|
|
|
2021-03-31 17:46:31 +08:00
|
|
|
<para>The functions <function>sd_bus_error_set()</function>, <function>sd_bus_error_setf()</function>,
|
|
|
|
and <function>sd_bus_error_set_const()</function> always return <constant>0</constant> when the specified
|
|
|
|
error value is <constant>NULL</constant>, and a negative errno-like value corresponding to the
|
|
|
|
<parameter>name</parameter> parameter otherwise. The functions
|
|
|
|
<function>sd_bus_error_set_errno()</function>, <function>sd_bus_error_set_errnof()</function> and
|
|
|
|
<function>sd_bus_error_set_errnofv()</function>, return <constant>0</constant> when the specified error
|
2021-06-30 19:53:14 +08:00
|
|
|
value is <constant>0</constant>, and a negative errno-like value corresponding to the
|
2021-03-31 17:46:31 +08:00
|
|
|
<parameter>error</parameter> parameter otherwise. If an error occurs internally, one of the negative
|
2022-05-26 20:04:52 +08:00
|
|
|
error values listed below will be returned. This allows those functions to be conveniently used in a
|
|
|
|
<constant>return</constant> statement, see the example below.</para>
|
2015-06-24 01:37:28 +08:00
|
|
|
|
|
|
|
<para><function>sd_bus_error_get_errno()</function> returns
|
2014-01-08 10:46:36 +08:00
|
|
|
<constant>false</constant> when <parameter>e</parameter> is
|
|
|
|
<constant>NULL</constant>, and a positive errno value mapped from
|
2014-02-17 10:58:37 +08:00
|
|
|
<parameter>e->name</parameter> otherwise.</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2021-03-31 17:46:31 +08:00
|
|
|
<para><function>sd_bus_error_copy()</function> and <function>sd_bus_error_move()</function> return a
|
2022-05-26 20:04:52 +08:00
|
|
|
negative error value converted from the source error, and zero if the error has not been set. This
|
|
|
|
allows those functions to be conveniently used in a <constant>return</constant> statement, see the
|
|
|
|
example below.</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2015-06-24 01:37:28 +08: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 10:46:36 +08:00
|
|
|
|
2020-08-23 00:24:43 +08:00
|
|
|
<para><function>sd_bus_error_has_name()</function>, <function>sd_bus_error_has_names()</function>, and
|
|
|
|
<function>sd_bus_error_has_names_sentinel()</function> return a non-zero value when <parameter>e</parameter> is
|
|
|
|
non-<constant>NULL</constant> and the <structfield>name</structfield> field is equal to one of the given
|
|
|
|
names, zero otherwise.</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2019-03-21 21:53:00 +08:00
|
|
|
<refsect2>
|
|
|
|
<title>Errors</title>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2022-05-26 20:04:52 +08:00
|
|
|
<para>Return value may indicate the following problems in the invocation of the function itself:</para>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2019-03-21 21:53:00 +08:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><constant>-EINVAL</constant></term>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2022-05-26 20:04:52 +08:00
|
|
|
<listitem><para>Error was already set in the <structname>sd_bus_error</structname> structure when
|
|
|
|
one the error-setting functions was called.</para></listitem>
|
2019-03-21 21:53:00 +08:00
|
|
|
</varlistentry>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2019-03-21 21:53:00 +08:00
|
|
|
<varlistentry>
|
|
|
|
<term><constant>-ENOMEM</constant></term>
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2019-03-21 21:53:00 +08:00
|
|
|
<listitem><para>Memory allocation failed.</para></listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2022-05-26 20:04:52 +08:00
|
|
|
|
|
|
|
<para>On success, <function>sd_bus_error_set()</function>, <function>sd_bus_error_setf()</function>,
|
|
|
|
<function>sd_bus_error_set_const()</function>, <function>sd_bus_error_set_errno()</function>,
|
|
|
|
<function>sd_bus_error_set_errnof()</function>, <function>sd_bus_error_set_errnofv()</function>,
|
|
|
|
<function>sd_bus_error_copy()</function>, and <function>sd_bus_error_move()</function> will return a
|
|
|
|
negative converted <varname>errno</varname>-style value, or <constant>0</constant> if the error
|
|
|
|
parameter is <constant>NULL</constant> or unset. D-Bus errors are converted to the integral
|
|
|
|
<varname>errno</varname>-style value, and the mapping mechanism is extensible, see the discussion
|
|
|
|
above. This effectively means that almost any negative <varname>errno</varname>-style value can be
|
|
|
|
returned.</para>
|
2019-03-21 21:53:00 +08:00
|
|
|
</refsect2>
|
2014-01-08 10:46:36 +08:00
|
|
|
</refsect1>
|
|
|
|
|
2022-05-26 20:04:52 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<example>
|
|
|
|
<title>Using the negative return value to propagate an error</title>
|
|
|
|
|
|
|
|
<programlisting><xi:include href="sd_bus_error-example.c" parse="text" /></programlisting>
|
|
|
|
</example>
|
|
|
|
</refsect1>
|
|
|
|
|
2018-06-06 17:59:04 +08:00
|
|
|
<xi:include href="libsystemd-pkgconfig.xml" />
|
2014-01-08 10:46:36 +08:00
|
|
|
|
2023-09-04 20:46:35 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>History</title>
|
2023-09-19 00:44:26 +08:00
|
|
|
<para><function>sd_bus_error_free()</function>,
|
|
|
|
<function>sd_bus_error_set()</function>,
|
|
|
|
<function>sd_bus_error_setf()</function>,
|
|
|
|
<function>sd_bus_error_set_const()</function>,
|
|
|
|
<function>sd_bus_error_set_errno()</function>,
|
|
|
|
<function>sd_bus_error_set_errnof()</function>,
|
|
|
|
<function>sd_bus_error_get_errno()</function>,
|
|
|
|
<function>sd_bus_error_copy()</function>,
|
|
|
|
<function>sd_bus_error_is_set()</function>, and
|
|
|
|
<function>sd_bus_error_has_name()</function> were added in version 209.</para>
|
2023-09-04 20:46:35 +08:00
|
|
|
<para><function>sd_bus_error_set_errnofv()</function> was added in version 223.</para>
|
|
|
|
<para><function>sd_bus_error_move()</function> was added in version 240.</para>
|
|
|
|
<para><function>sd_bus_error_has_names_sentinel()</function> was added in version 247.</para>
|
|
|
|
<para><function>sd_bus_error_setfv()</function> was added in version 252.</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2014-01-08 10:46:36 +08: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-24 01:37:28 +08: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 06:25:54 +08:00
|
|
|
<citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
2022-10-10 17:00:57 +08:00
|
|
|
<citerefentry project='man-pages'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
2014-01-08 10:46:36 +08:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|