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+
8 Copyright 2015 Lennart Poettering
11 <refentry id="sd_bus_error_add_map">
14 <title>sd_bus_error_add_map</title>
15 <productname>systemd</productname>
19 <contrib>Developer</contrib>
20 <firstname>Lennart</firstname>
21 <surname>Poettering</surname>
22 <email>lennart@poettering.net</email>
28 <refentrytitle>sd_bus_error_add_map</refentrytitle>
29 <manvolnum>3</manvolnum>
33 <refname>sd_bus_error_add_map</refname>
34 <refname>sd_bus_error_map</refname>
35 <refname>SD_BUS_ERROR_MAP</refname>
36 <refname>SD_BUS_ERROR_END</refname>
38 <refpurpose>Additional sd-dbus error mappings</refpurpose>
43 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
45 <funcsynopsisinfo>typedef struct {
49 } sd_bus_error_map;</funcsynopsisinfo>
54 <constant>SD_BUS_ERROR_MAP(<replaceable>name</replaceable>, <replaceable>code</replaceable>)</constant>
57 <constant>SD_BUS_ERROR_MAP_END</constant>
61 <funcdef>int <function>sd_bus_error_add_map</function></funcdef>
62 <paramdef>const sd_bus_map *<parameter>map</parameter></paramdef>
68 <title>Description</title>
70 <para>The <function>sd_bus_error_add_map()</function> call may be
71 used to register additional mappings for converting D-Bus errors
72 to Linux <varname>errno</varname>-style errors. The mappings
73 defined with this call are consulted by calls such as
74 <citerefentry><refentrytitle>sd_bus_error_set</refentrytitle><manvolnum>3</manvolnum></citerefentry>
76 <citerefentry><refentrytitle>sd_bus_error_get_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>. By
77 default, a number of generic, standardized mappings are known, as
79 <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Use
80 this call to add further, application-specific mappings.</para>
82 <para>The function takes a pointer to an array of
83 <structname>sd_bus_error_map</structname> structures. A reference
84 to the specified array is added to the lookup tables for error
85 mappings. Note that the structure is not copied, and that it is hence
86 essential that the array stays available and constant during the
87 entire remaining runtime of the process.</para>
89 <para>The mapping array should be put together with a series of
90 <constant>SD_BUS_ERROR_MAP()</constant> macro invocations that
91 take a literal name string and a (positive)
92 <varname>errno</varname>-style error number. The last entry of the
93 array should be an invocation of the
94 <constant>SD_BUS_ERROR_MAP_END</constant> macro. The array should not be
95 put together without use of these two macros.</para>
97 <para>Note that the call is idempotent: it is safe to invoke it
98 multiple times with the parameter, which will only add the passed
99 mapping array once.</para>
101 <para>Note that the memory allocated by this call is not intended
102 to be freed during the lifetime of the process. It should not be
103 freed explicitly.</para>
107 <title>Return Value</title>
109 <para><function>sd_bus_error_add_map()</function> returns a
110 positive value when the new array was added to the lookup
111 tables. It returns zero when the same array was already added
112 before. On error, a negative <varname>errno</varname>-style error
113 code is returned. See below for known error codes.</para>
117 <title>Errors</title>
119 <para>Returned errors may indicate the following problems:</para>
124 <term><constant>-EINVAL</constant></term>
126 <listitem><para>The specified mapping array is invalid.</para></listitem>
130 <term><constant>-ENOMEM</constant></term>
132 <listitem><para>Memory allocation failed.</para></listitem>
140 <para>The various error definitions described here are available
141 as a shared library, which can be compiled and linked to with the
142 <constant>libelogind</constant> <citerefentry
143 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
148 <title>See Also</title>
151 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
153 <citerefentry><refentrytitle>sd_bus_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154 <citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
155 <citerefentry project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156 <citerefentry project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry>