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 - sd-bus error handling
12

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

153       The functions sd_bus_error_set(), sd_bus_error_setf(), and
154       sd_bus_error_set_const(), when successful, return the negative errno
155       value corresponding to the name parameter. The functions
156       sd_bus_error_set_errno(), sd_bus_error_set_errnof() and
157       sd_bus_error_set_errnofv(), when successful, return the negative value
158       of the error parameter. If an error occurs, one of the negative error
159       values listed below will be returned.
160
161       sd_bus_error_get_errno() returns false when e is NULL, and a positive
162       errno value mapped from e->name otherwise.
163
164       sd_bus_error_copy() and sd_bus_error_move() return 0 or a positive
165       integer on success, and a negative error value converted from the error
166       name otherwise.
167
168       sd_bus_error_is_set() returns a non-zero value when e and the name
169       field are non-NULL, zero otherwise.
170
171       sd_bus_error_has_name() returns a non-zero value when e is non-NULL and
172       the name field is equal to name, zero otherwise.
173

REFERENCE OWNERSHIP

175       sd_bus_error is not reference counted. Users should destroy resources
176       held by it by calling sd_bus_error_free(). Usually, error structures
177       are allocated on the stack or passed in as function parameters, but
178       they may also be allocated dynamically, in which case it is the duty of
179       the caller to free(3) the memory held by the structure itself after
180       freeing its contents with sd_bus_error_free().
181
182   Errors
183       Returned errors may indicate the following problems:
184
185       -EINVAL
186           Error was already set in sd_bus_error structure when one the
187           error-setting functions was called.
188
189       -ENOMEM
190           Memory allocation failed.
191

NOTES

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

SEE ALSO

197       systemd(1), sd-bus(3), sd-bus-errors(3), sd_bus_error_add_map(3),
198       errno(3), strerror_r(3)
199

NOTES

201        1. Valid Names
202           http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
203
204
205
206systemd 245                                                    SD_BUS_ERROR(3)
Impressum