1SD_BUS_ERROR(3)                  sd_bus_error                  SD_BUS_ERROR(3)
2
3
4

NAME

6       sd_bus_error, SD_BUS_ERROR_MAKE_CONST, SD_BUS_ERROR_NULL,
7       sd_bus_error_free, sd_bus_error_set, sd_bus_error_setf,
8       sd_bus_error_set_const, sd_bus_error_set_errno,
9       sd_bus_error_set_errnof, sd_bus_error_set_errnofv,
10       sd_bus_error_get_errno, sd_bus_error_copy, sd_bus_error_move,
11       sd_bus_error_is_set, sd_bus_error_has_name,
12       sd_bus_error_has_names_sentinel, sd_bus_error_has_names - sd-bus error
13       handling
14

SYNOPSIS

16       #include <systemd/sd-bus.h>
17
18       typedef struct {
19               const char *name;
20               const char *message;
21               ...
22       } sd_bus_error;
23
24       SD_BUS_ERROR_MAKE_CONST(name, message)
25
26       SD_BUS_ERROR_NULL
27
28       void sd_bus_error_free(sd_bus_error *e);
29
30       int sd_bus_error_set(sd_bus_error *e, const char *name,
31                            const char *message);
32
33       int sd_bus_error_setf(sd_bus_error *e, const char *name,
34                             const char *format, ...);
35
36       int sd_bus_error_set_const(sd_bus_error *e, const char *name,
37                                  const char *message);
38
39       int sd_bus_error_set_errno(sd_bus_error *e, int error);
40
41       int sd_bus_error_set_errnof(sd_bus_error *e, int error,
42                                   const char *format, ...);
43
44       int sd_bus_error_set_errnofv(sd_bus_error *e, int error,
45                                    const char *format, va_list ap);
46
47       int sd_bus_error_get_errno(const sd_bus_error *e);
48
49       int sd_bus_error_copy(sd_bus_error *dst, const sd_bus_error *e);
50
51       int sd_bus_error_move(sd_bus_error *dst, sd_bus_error *e);
52
53       int sd_bus_error_is_set(const sd_bus_error *e);
54
55       int sd_bus_error_has_name(const sd_bus_error *e, const char *name);
56
57       int sd_bus_error_has_names_sentinel(const sd_bus_error *e, ...);
58
59       #define sd_bus_error_has_names(e, ...)
60       sd_bus_error_has_names_sentinel(e, ..., NULL)
61

DESCRIPTION

63       The sd_bus_error structure carries information about a D-Bus error
64       condition, or lack thereof. The functions described below may be used
65       to set and query fields in this structure.
66
67       •   The name field contains a short identifier of an error. It should
68           follow the rules for error names described in the D-Bus
69           specification, subsection Valid Names[1]. A number of common,
70           standardized error names are described in sd-bus-errors(3), but
71           additional domain-specific errors may be defined by applications.
72
73       •   The message field usually contains a human-readable string
74           describing the details, but might be NULL.
75
76       An unset sd_bus_error structure should have both fields initialized to
77       NULL, and signifies lack of an error, i.e. success. Assign
78       SD_BUS_ERROR_NULL to the structure in order to initialize both fields
79       to NULL. When no longer necessary, resources held by the sd_bus_error
80       structure should be destroyed with sd_bus_error_free().
81
82       sd_bus_error_set() sets an error structure to the specified name and
83       message strings. The strings will be copied into internal, newly
84       allocated memory. It is essential to free the contents again when they
85       are not required anymore (see above). Do not use this call on error
86       structures that have already been set. If you intend to reuse an error
87       structure, free the old data stored in it with sd_bus_error_free()
88       first.
89
90       sd_bus_error_set() will return an errno-like value (see errno(3))
91       determined from the specified error name name. If name is NULL, it is
92       assumed that no error occurred, and 0 is returned. If name is nonnull,
93       a negative value is always returned. If e is NULL, no error structure
94       is initialized, but name is still converted into an errno-style value.
95
96       Various well-known D-Bus errors are converted to well-known errno
97       counterparts, and the other ones to -EIO. See sd-bus-errors(3) for a
98       list of well-known error names. Additional error mappings may be
99       defined with sd_bus_error_add_map(3).
100
101       sd_bus_error_set() is designed to be conveniently used in a return
102       statement. If message is NULL, no message is set. This call can fail if
103       no memory may be allocated for the name and message strings, in which
104       case an SD_BUS_ERROR_NO_MEMORY error will be set instead and -ENOMEM
105       returned.
106
107       sd_bus_error_setf() is similar to sd_bus_error_set(), but takes a
108       printf(3) format string and corresponding arguments to generate the
109       message field.
110
111       sd_bus_error_set_const() is similar to sd_bus_error_set(), but the
112       string parameters are not copied internally, and must hence remain
113       constant and valid for the lifetime of e. Use this call to avoid memory
114       allocations when setting error structures. Since this call does not
115       allocate memory, it will not fail with an out-of-memory condition as
116       sd_bus_error_set() may, as described above. Alternatively, the
117       SD_BUS_ERROR_MAKE_CONST() macro may be used to generate a literal,
118       constant bus error structure on-the-fly.
119
120       sd_bus_error_set_errno() will immediately return 0 if the specified
121       error parameter error is 0. Otherwise, it will set name from an
122       errno-like value that is converted to a D-Bus error.  strerror_r(3)
123       will be used to set message. Well-known D-Bus error names will be used
124       for name if applicable, otherwise a name in the "System.Error."
125       namespace will be generated. The sign of the specified error number is
126       ignored and the absolute value is used implicitly. If the specified
127       error error is non-zero, the call always returns a negative value, for
128       convenient usage in return statements. This call might fail due to lack
129       of memory, in which case an SD_BUS_ERROR_NO_MEMORY error is set
130       instead, and -ENOMEM is returned.
131
132       sd_bus_error_set_errnof() is similar to sd_bus_error_set_errno(), but
133       in addition to error, takes a printf(3) format string and corresponding
134       arguments. The message field will be generated from format and the
135       arguments.
136
137       sd_bus_error_set_errnofv() is similar to sd_bus_error_set_errnof(), but
138       takes the format string parameters as va_arg(3) parameter list.
139
140       sd_bus_error_get_errno() converts the name field of an error structure
141       to an errno-like (positive) value using the same rules as
142       sd_bus_error_set(). If e is NULL, 0 will be returned.
143
144       sd_bus_error_copy() will initialize dst using the values in e, if e has
145       been set with an error value before. Otherwise, it will return
146       immediately. If the strings in e were set using
147       sd_bus_error_set_const(), they will be shared. Otherwise, they will be
148       copied. Returns a converted errno-like, negative error code or 0.
149       Before this call, dst must be unset, i.e. either freshly initialized
150       with NULL or reset using sd_bus_error_free().
151
152       sd_bus_error_move() is similar to sd_bus_error_copy(), but will move
153       any error information from e into dst, resetting the former. This
154       function cannot fail, as no new memory is allocated. Note that if e is
155       not set, dst is initialized to SD_BUS_ERROR_NULL. Moreover, if dst is
156       NULL no operation is executed on it and resources held by e are freed
157       and reset. Returns a converted errno-like, non-positive error value.
158
159       sd_bus_error_is_set() will return a non-zero value if e is non-NULL and
160       an error has been set, false otherwise.
161
162       sd_bus_error_has_name() will return a non-zero value if e is non-NULL
163       and an error with the same name has been set, false otherwise.
164
165       sd_bus_error_has_names_sentinel() is similar to
166       sd_bus_error_has_name(), but takes multiple names to check against. The
167       list must be terminated with NULL.  sd_bus_error_has_names() is a macro
168       wrapper around sd_bus_error_has_names_sentinel() that adds the NULL
169       sentinel automatically.
170
171       sd_bus_error_free() will destroy resources held by e. The parameter
172       itself will not be deallocated, and must be free(3)d by the caller if
173       necessary. The function may also be called safely on unset errors
174       (error structures with both fields set to NULL), in which case it
175       performs no operation. This call will reset the error structure after
176       freeing the data, so that all fields are set to NULL. The structure may
177       be reused afterwards.
178

RETURN VALUE

180       The functions sd_bus_error_set(), sd_bus_error_setf(), and
181       sd_bus_error_set_const() always return 0 when the specified error value
182       is NULL, and a negative errno-like value corresponding to the name
183       parameter otherwise. The functions sd_bus_error_set_errno(),
184       sd_bus_error_set_errnof() and sd_bus_error_set_errnofv(), return 0 when
185       the specified error value is 0, and a negative errno-like value
186       corresponding to the error parameter otherwise. If an error occurs
187       internally, one of the negative error values listed below will be
188       returned.
189
190       sd_bus_error_get_errno() returns false when e is NULL, and a positive
191       errno value mapped from e->name otherwise.
192
193       sd_bus_error_copy() and sd_bus_error_move() return a negative error
194       value converted from the source error, and zero if the error has not
195       been set.
196
197       sd_bus_error_is_set() returns a non-zero value when e and the name
198       field are non-NULL, zero otherwise.
199
200       sd_bus_error_has_name(), sd_bus_error_has_names(), and
201       sd_bus_error_has_names_sentinel() return a non-zero value when e is
202       non-NULL and the name field is equal to one of the given names, zero
203       otherwise.
204

REFERENCE OWNERSHIP

206       sd_bus_error is not reference counted. Users should destroy resources
207       held by it by calling sd_bus_error_free(). Usually, error structures
208       are allocated on the stack or passed in as function parameters, but
209       they may also be allocated dynamically, in which case it is the duty of
210       the caller to free(3) the memory held by the structure itself after
211       freeing its contents with sd_bus_error_free().
212
213   Errors
214       Returned errors may indicate the following problems:
215
216       -EINVAL
217           Error was already set in sd_bus_error structure when one the
218           error-setting functions was called.
219
220       -ENOMEM
221           Memory allocation failed.
222

NOTES

224       These APIs are implemented as a shared library, which can be compiled
225       and linked to with the libsystemd pkg-config(1) file.
226

SEE ALSO

228       systemd(1), sd-bus(3), sd-bus-errors(3), sd_bus_error_add_map(3),
229       errno(3), strerror_r(3)
230

NOTES

232        1. Valid Names
233           http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
234
235
236
237systemd 249                                                    SD_BUS_ERROR(3)
Impressum