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

RETURN VALUE

166       The functions sd_bus_error_set(), sd_bus_error_setf(), and
167       sd_bus_error_set_const(), when successful, return the negative errno
168       value corresponding to the name parameter. The functions
169       sd_bus_error_set_errno(), sd_bus_error_set_errnof() and
170       sd_bus_error_set_errnofv(), when successful, return the negative value
171       of the error parameter. If an error occurs, one of the negative error
172       values listed below will be returned.
173
174       sd_bus_error_get_errno() returns false when e is NULL, and a positive
175       errno value mapped from e->name otherwise.
176
177       sd_bus_error_copy() and sd_bus_error_move() return 0 or a positive
178       integer on success, and a negative error value converted from the error
179       name otherwise.
180
181       sd_bus_error_is_set() returns a non-zero value when e and the name
182       field are non-NULL, zero otherwise.
183
184       sd_bus_error_has_name(), sd_bus_error_has_names(), and
185       sd_bus_error_has_names_sentinel() return a non-zero value when e is
186       non-NULL and the name field is equal to one of the given names, zero
187       otherwise.
188

REFERENCE OWNERSHIP

190       sd_bus_error is not reference counted. Users should destroy resources
191       held by it by calling sd_bus_error_free(). Usually, error structures
192       are allocated on the stack or passed in as function parameters, but
193       they may also be allocated dynamically, in which case it is the duty of
194       the caller to free(3) the memory held by the structure itself after
195       freeing its contents with sd_bus_error_free().
196
197   Errors
198       Returned errors may indicate the following problems:
199
200       -EINVAL
201           Error was already set in sd_bus_error structure when one the
202           error-setting functions was called.
203
204       -ENOMEM
205           Memory allocation failed.
206

NOTES

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

SEE ALSO

212       systemd(1), sd-bus(3), sd-bus-errors(3), sd_bus_error_add_map(3),
213       errno(3), strerror_r(3)
214

NOTES

216        1. Valid Names
217           http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
218
219
220
221systemd 248                                                    SD_BUS_ERROR(3)
Impressum