mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-27 18:55:09 +03:00
basic,bus-error: return negative error from errno_from_name
errno_from_name used an unusual return convention where 0 meant "not found". This tripped up config_parse_syscall_errno(), which would treat that as success. Return -EINVAL instead, and adjust bus_error_name_to_errno() for the new convention. Also remove a goto which was used as a simple if and clean up surroudning code a bit.
This commit is contained in:
parent
9c4615fb09
commit
d469dd44c4
@ -25,7 +25,7 @@
|
||||
#include "macro.h"
|
||||
|
||||
static const struct errno_name* lookup_errno(register const char *str,
|
||||
register unsigned int len);
|
||||
register unsigned int len);
|
||||
|
||||
#include "errno-from-name.h"
|
||||
#include "errno-to-name.h"
|
||||
@ -48,8 +48,9 @@ int errno_from_name(const char *name) {
|
||||
|
||||
sc = lookup_errno(name, strlen(name));
|
||||
if (!sc)
|
||||
return 0;
|
||||
return -EINVAL;
|
||||
|
||||
assert(sc->id > 0);
|
||||
return sc->id;
|
||||
}
|
||||
|
||||
|
@ -93,14 +93,14 @@ static int bus_error_name_to_errno(const char *name) {
|
||||
p = startswith(name, "System.Error.");
|
||||
if (p) {
|
||||
r = errno_from_name(p);
|
||||
if (r <= 0)
|
||||
if (r < 0)
|
||||
return EIO;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
if (additional_error_maps) {
|
||||
for (map = additional_error_maps; *map; map++) {
|
||||
if (additional_error_maps)
|
||||
for (map = additional_error_maps; *map; map++)
|
||||
for (m = *map;; m++) {
|
||||
/* For additional error maps the end marker is actually the end marker */
|
||||
if (m->code == BUS_ERROR_MAP_END_MARKER)
|
||||
@ -109,15 +109,13 @@ static int bus_error_name_to_errno(const char *name) {
|
||||
if (streq(m->name, name))
|
||||
return m->code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = __start_BUS_ERROR_MAP;
|
||||
while (m < __stop_BUS_ERROR_MAP) {
|
||||
/* For magic ELF error maps, the end marker might
|
||||
* appear in the middle of things, since multiple maps
|
||||
* might appear in the same section. Hence, let's skip
|
||||
* over it, but realign the pointer to the netx 8byte
|
||||
* over it, but realign the pointer to the next 8 byte
|
||||
* boundary, which is the selected alignment for the
|
||||
* arrays. */
|
||||
if (m->code == BUS_ERROR_MAP_END_MARKER) {
|
||||
@ -258,25 +256,24 @@ int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_li
|
||||
|
||||
if (!name)
|
||||
return 0;
|
||||
if (!e)
|
||||
goto finish;
|
||||
|
||||
assert_return(!bus_error_is_dirty(e), -EINVAL);
|
||||
if (e) {
|
||||
assert_return(!bus_error_is_dirty(e), -EINVAL);
|
||||
|
||||
e->name = strdup(name);
|
||||
if (!e->name) {
|
||||
*e = BUS_ERROR_OOM;
|
||||
return -ENOMEM;
|
||||
e->name = strdup(name);
|
||||
if (!e->name) {
|
||||
*e = BUS_ERROR_OOM;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* If we hit OOM on formatting the pretty message, we ignore
|
||||
* this, since we at least managed to write the error name */
|
||||
if (format)
|
||||
(void) vasprintf((char**) &e->message, format, ap);
|
||||
|
||||
e->_need_free = 1;
|
||||
}
|
||||
|
||||
/* If we hit OOM on formatting the pretty message, we ignore
|
||||
* this, since we at least managed to write the error name */
|
||||
if (format)
|
||||
(void) vasprintf((char**) &e->message, format, ap);
|
||||
|
||||
e->_need_free = 1;
|
||||
|
||||
finish:
|
||||
return -bus_error_name_to_errno(name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user