<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
- "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+ "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="sd_bus_error" xmlns:xi="http://www.w3.org/2001/XInclude">
<refname>sd_bus_error_free</refname>
<refname>sd_bus_error_set</refname>
<refname>sd_bus_error_setf</refname>
+ <refname>sd_bus_error_setfv</refname>
<refname>sd_bus_error_set_const</refname>
<refname>sd_bus_error_set_errno</refname>
<refname>sd_bus_error_set_errnof</refname>
const char *message;
…
} sd_bus_error;</funcsynopsisinfo>
+ </funcsynopsis>
- <para>
- <constant>SD_BUS_ERROR_MAKE_CONST(<replaceable>name</replaceable>, <replaceable>message</replaceable>)</constant>
- </para>
- <para>
- <constant>SD_BUS_ERROR_NULL</constant>
- </para>
+ <para>
+ <constant>SD_BUS_ERROR_MAKE_CONST(<replaceable>name</replaceable>, <replaceable>message</replaceable>)</constant>
+ </para>
+ <para>
+ <constant>SD_BUS_ERROR_NULL</constant>
+ </para>
+ <funcsynopsis>
<funcprototype>
<funcdef>void <function>sd_bus_error_free</function></funcdef>
<paramdef>sd_bus_error *<parameter>e</parameter></paramdef>
<paramdef>…</paramdef>
</funcprototype>
+ <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>
+
<funcprototype>
<funcdef>int <function>sd_bus_error_set_const</function></funcdef>
<paramdef>sd_bus_error *<parameter>e</parameter></paramdef>
<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>
</funcsynopsis>
+ <para>
+ #define sd_bus_error_has_names(e, ...) sd_bus_error_has_names_sentinel(e, ..., NULL)
+ </para>
+
</refsynopsisdiv>
<refsect1>
<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
- url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
- Names</ulink>. A number of common, standardized error names are described in
+ url="https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
+ D-Bus 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>
which case an <constant>SD_BUS_ERROR_NO_MEMORY</constant> error will be set instead and
<constant>-ENOMEM</constant> returned. </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_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>
<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
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>
- <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
- <parameter>format</parameter> and the arguments.</para>
-
- <para><function>sd_bus_error_set_errnofv()</function> is similar to
- <function>sd_bus_error_set_errnof()</function>, but takes the
- format string parameters as <citerefentry
+ <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
project='man-pages'><refentrytitle>va_arg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
parameter list.</para>
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
- copied. Returns a converted <varname>errno</varname>-like, negative error code or <constant>0</constant>.
- Before this call, <parameter>dst</parameter> must be unset, i.e. either freshly initialized with
+ copied. Before this call, <parameter>dst</parameter> must be unset, i.e. either freshly initialized with
<constant>NULL</constant> or reset using <function>sd_bus_error_free()</function>.</para>
+ <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>
+
<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, <parameter>dst</parameter> is initializated to
+ <parameter>e</parameter> is not set, <parameter>dst</parameter> is initialized to
<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>
to <constant>NULL</constant>. The structure may be reused afterwards.</para>
</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 <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>
+
<refsect1>
<title>Return Value</title>
<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
- value is <constant>0</constant>, and a a negative errno-like value corresponding to the
+ value is <constant>0</constant>, and a negative errno-like value corresponding to the
<parameter>error</parameter> parameter otherwise. If an error occurs internally, one of the negative
- error values listed below will be returned.</para>
+ 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>
<para><function>sd_bus_error_get_errno()</function> returns
<constant>false</constant> when <parameter>e</parameter> is
<parameter>e->name</parameter> otherwise.</para>
<para><function>sd_bus_error_copy()</function> and <function>sd_bus_error_move()</function> return a
- negative error value converted from the source error, and zero if the error has not been set.</para>
+ 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>
<para><function>sd_bus_error_is_set()</function> returns a
non-zero value when <parameter>e</parameter> and the
<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>
- </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
- <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>
<refsect2>
<title>Errors</title>
- <para>Returned errors may indicate the following problems:</para>
+ <para>Return value may indicate the following problems in the invocation of the function itself:</para>
<variablelist>
-
<varlistentry>
<term><constant>-EINVAL</constant></term>
- <listitem><para>Error was already set in <structname>sd_bus_error</structname> structure when one
- the error-setting functions was called.</para></listitem>
+ <listitem><para>Error was already set in the <structname>sd_bus_error</structname> structure when
+ one the error-setting functions was called.</para></listitem>
</varlistentry>
<varlistentry>
<listitem><para>Memory allocation failed.</para></listitem>
</varlistentry>
</variablelist>
+
+ <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>
</refsect2>
</refsect1>
+ <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>
+
<xi:include href="libsystemd-pkgconfig.xml" />
+ <refsect1>
+ <title>History</title>
+ <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_set_errnofv()</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 221.</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>
+
<refsect1>
<title>See Also</title>
- <para>
- <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry>
- </para>
+ <para><simplelist type="inline">
+ <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
+ <member><citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+ <member><citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+ <member><citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+ <member><citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+ <member><citerefentry project='man-pages'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
+ </simplelist></para>
</refsect1>
</refentry>