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">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id="sd_bus_error_add_map">
12 <title>sd_bus_error_add_map</title>
13 <productname>systemd</productname>
17 <contrib>Developer</contrib>
18 <firstname>Lennart</firstname>
19 <surname>Poettering</surname>
20 <email>lennart@poettering.net</email>
26 <refentrytitle>sd_bus_error_add_map</refentrytitle>
27 <manvolnum>3</manvolnum>
31 <refname>sd_bus_error_add_map</refname>
32 <refname>sd_bus_error_map</refname>
33 <refname>SD_BUS_ERROR_MAP</refname>
34 <refname>SD_BUS_ERROR_END</refname>
36 <refpurpose>Additional sd-dbus error mappings</refpurpose>
41 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
43 <funcsynopsisinfo>typedef struct {
47 } sd_bus_error_map;</funcsynopsisinfo>
52 <constant>SD_BUS_ERROR_MAP(<replaceable>name</replaceable>, <replaceable>code</replaceable>)</constant>
55 <constant>SD_BUS_ERROR_MAP_END</constant>
59 <funcdef>int <function>sd_bus_error_add_map</function></funcdef>
60 <paramdef>const sd_bus_map *<parameter>map</parameter></paramdef>
66 <title>Description</title>
68 <para>The <function>sd_bus_error_add_map()</function> call may be
69 used to register additional mappings for converting D-Bus errors
70 to Linux <varname>errno</varname>-style errors. The mappings
71 defined with this call are consulted by calls such as
72 <citerefentry><refentrytitle>sd_bus_error_set</refentrytitle><manvolnum>3</manvolnum></citerefentry>
74 <citerefentry><refentrytitle>sd_bus_error_get_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>. By
75 default, a number of generic, standardized mappings are known, as
77 <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Use
78 this call to add further, application-specific mappings.</para>
80 <para>The function takes a pointer to an array of
81 <structname>sd_bus_error_map</structname> structures. A reference
82 to the specified array is added to the lookup tables for error
83 mappings. Note that the structure is not copied, and that it is hence
84 essential that the array stays available and constant during the
85 entire remaining runtime of the process.</para>
87 <para>The mapping array should be put together with a series of
88 <constant>SD_BUS_ERROR_MAP()</constant> macro invocations that
89 take a literal name string and a (positive)
90 <varname>errno</varname>-style error number. The last entry of the
91 array should be an invocation of the
92 <constant>SD_BUS_ERROR_MAP_END</constant> macro. The array should not be
93 put together without use of these two macros.</para>
95 <para>Note that the call is idempotent: it is safe to invoke it
96 multiple times with the parameter, which will only add the passed
97 mapping array once.</para>
99 <para>Note that the memory allocated by this call is not intended
100 to be freed during the lifetime of the process. It should not be
101 freed explicitly.</para>
105 <title>Return Value</title>
107 <para><function>sd_bus_error_add_map()</function> returns a
108 positive value when the new array was added to the lookup
109 tables. It returns zero when the same array was already added
110 before. On error, a negative <varname>errno</varname>-style error
111 code is returned. See below for known error codes.</para>
115 <title>Errors</title>
117 <para>Returned errors may indicate the following problems:</para>
122 <term><constant>-EINVAL</constant></term>
124 <listitem><para>The specified mapping array is invalid.</para></listitem>
128 <term><constant>-ENOMEM</constant></term>
130 <listitem><para>Memory allocation failed.</para></listitem>
138 <para>The various error definitions described here are available
139 as a shared library, which can be compiled and linked to with the
140 <constant>libelogind</constant> <citerefentry
141 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
146 <title>See Also</title>
149 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>sd_bus_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
153 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154 <citerefentry project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry>