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_message_new_method_error"
10 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
13 <title>sd_bus_message_new_method_error
</title>
14 <productname>systemd
</productname>
18 <refentrytitle>sd_bus_message_new_method_error
</refentrytitle>
19 <manvolnum>3</manvolnum>
23 <refname>sd_bus_message_new_method_error
</refname>
24 <refname>sd_bus_message_new_method_errorf
</refname>
25 <refname>sd_bus_message_new_method_errno
</refname>
26 <refname>sd_bus_message_new_method_errnof
</refname>
28 <refpurpose>Create a an error reply for a method call
</refpurpose>
33 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
36 <funcdef>int sd_bus_message_new_method_error
</funcdef>
37 <paramdef>sd_bus_message *
<parameter>call
</parameter></paramdef>
38 <paramdef>sd_bus_message **
<parameter>m
</parameter></paramdef>
39 <paramdef>const sd_bus_error *
<parameter>e
</parameter></paramdef>
43 <funcdef>int sd_bus_message_new_method_errorf
</funcdef>
44 <paramdef>sd_bus_message *
<parameter>call
</parameter></paramdef>
45 <paramdef>sd_bus_message **
<parameter>m
</parameter></paramdef>
46 <paramdef>const char *
<parameter>name
</parameter></paramdef>
47 <paramdef>const char *
<parameter>format
</parameter></paramdef>
48 <paramdef>…
</paramdef>
52 <funcdef>int sd_bus_message_new_method_errno
</funcdef>
53 <paramdef>sd_bus_message *
<parameter>call
</parameter></paramdef>
54 <paramdef>sd_bus_message **
<parameter>m
</parameter></paramdef>
55 <paramdef>int
<parameter>error
</parameter></paramdef>
56 <paramdef>const sd_bus_error *
<parameter>p
</parameter></paramdef>
60 <funcdef>int sd_bus_message_new_method_errnof
</funcdef>
61 <paramdef>sd_bus_message *
<parameter>call
</parameter></paramdef>
62 <paramdef>sd_bus_message **
<parameter>m
</parameter></paramdef>
63 <paramdef>int
<parameter>error
</parameter></paramdef>
64 <paramdef>const char *
<parameter>format
</parameter></paramdef>
65 <paramdef>…
</paramdef>
71 <title>Description
</title>
73 <para>The
<function>sd_bus_message_new_method_error()
</function> function creates
74 a new bus message object that is an error reply to the
75 <parameter>call
</parameter> message, and returns it in the
76 <parameter>m
</parameter> output parameter. The error information from error
77 <parameter>e
</parameter> is appended: the
<parameter>name
</parameter> field of
78 <parameter>e
</parameter> is used as the error identifier in the reply header (for
79 example an error name such as
80 <literal>org.freedesktop.DBus.Error.NotSupported
</literal> or the equivalent
81 symbolic
<constant>SD_BUS_ERROR_NOT_SUPPORTED
</constant>), and the
82 <parameter>message
</parameter> field is set as the human readable error message
83 string if present. The error
<parameter>e
</parameter> must have the
84 <parameter>name
</parameter> field set, see
85 <citerefentry><refentrytitle>sd_bus_error_is_set
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
88 <para>The
<function>sd_bus_message_new_method_errorf()
</function> function
89 creates an error reply similarly to
90 <function>sd_bus_message_new_method_error()
</function>, but instead of a ready
91 error structure, it takes an error identifier string
<parameter>name
</parameter>,
93 project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
94 format string
<parameter>format
</parameter> and corresponding arguments. An error
95 reply is sent with the error identifier
<parameter>name
</parameter> and the
96 formatted string as the message.
<parameter>name
</parameter> and
97 <parameter>format
</parameter> must not be
<constant>NULL
</constant>.
100 <para>The
<function>sd_bus_message_new_method_errno()
</function> function creates
101 an error reply similarly to
102 <function>sd_bus_message_new_method_error()
</function>, but in addition to the
103 error structure
<parameter>p
</parameter>, it takes an
104 <citerefentry><refentrytitle>errno
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
105 error value in parameter
<parameter>error
</parameter>. If the error
106 <parameter>p
</parameter> is set (see
107 <citerefentry><refentrytitle>sd_bus_error_is_set
</refentrytitle><manvolnum>3</manvolnum></citerefentry>),
108 it is used in the reply. Otherwise,
<parameter>error
</parameter> is translated to
109 an error identifier and used to create a new error structure using
110 <citerefentry><refentrytitle>sd_bus_error_set_errno
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
111 and that is used in the reply. (If
<parameter>error
</parameter> is zero, no error
112 is actually set, and an error reply with no information is created.)
</para>
114 <para>The
<function>sd_bus_message_new_method_errnof()
</function> function
115 creates an error reply similarly to
116 <function>sd_bus_message_new_method_error()
</function>. It takes an
117 <citerefentry><refentrytitle>errno
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
118 error value in parameter
<parameter>error
</parameter>, plus a
<citerefentry
119 project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
120 format string
<parameter>format
</parameter> and corresponding arguments.
121 <literal>%m
</literal> may be used in the format string to refer to the error
122 string corresponding to the specified errno code. The error message is initalized
123 using the error identifier generated from
<constant>error
</constant> and the
124 formatted string. (If
<parameter>error
</parameter> is zero, no error is actually
125 set, and an error reply with no information is created.)
</para>
129 <title>Return Value
</title>
131 <para>These functions return
0 if the error reply was successfully created, and a
132 negative errno-style error code otherwise.
</para>
135 <refsect1 id='errors'
>
136 <title>Errors
</title>
138 <para>Returned errors may indicate the following problems:
</para>
142 <term><constant>-EINVAL
</constant></term>
144 <listitem><para>The call message
<parameter>call
</parameter> or the output
145 parameter
<parameter>m
</parameter> are
<constant>NULL
</constant>.
</para>
147 <para>Message
<parameter>call
</parameter> is not a method call
150 <para>The error
<parameter>error
</parameter> parameter to
151 <function>sd_bus_message_new_method_error
</function> is not set, see
152 <citerefentry><refentrytitle>sd_bus_error_is_set
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
158 <term><constant>-EPERM
</constant></term>
160 <listitem><para>Message
<parameter>call
</parameter> has been sealed.
165 <term><constant>-ENOTCONN
</constant></term>
167 <listitem><para>The bus to which message
<parameter>call
</parameter> is
168 attached is not connected.
</para></listitem>
172 <term><constant>-ENOMEM
</constant></term>
174 <listitem><para>Memory allocation failed.
</para></listitem>
179 <xi:include href=
"libsystemd-pkgconfig.xml" />
182 <title>See Also
</title>
185 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
186 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>