diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-error.c | 16 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-error.h | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 4 | ||||
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/sd-bus.h | 4 |
5 files changed, 18 insertions, 10 deletions
diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c index 0832022ee9..015fae70ad 100644 --- a/src/libsystemd-bus/bus-error.c +++ b/src/libsystemd-bus/bus-error.c @@ -31,6 +31,13 @@ #include "sd-bus.h" #include "bus-error.h" +bool bus_error_is_dirty(sd_bus_error *e) { + if (!e) + return 0; + + return e->name || e->message || e->need_free; +} + void sd_bus_error_free(sd_bus_error *e) { if (!e) return; @@ -51,7 +58,7 @@ int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...) if (!e) return 0; - if (sd_bus_error_is_set(e)) + if (bus_error_is_dirty(e)) return -EINVAL; if (!name) return -EINVAL; @@ -81,7 +88,7 @@ int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...) int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e) { if (!dest) return 0; - if (sd_bus_error_is_set(dest)) + if (bus_error_is_dirty(dest)) return -EINVAL; if (!sd_bus_error_is_set(e)) return 0; @@ -113,18 +120,19 @@ int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e) { void sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message) { if (!e) return; - if (sd_bus_error_is_set(e)) + if (bus_error_is_dirty(e)) return; e->name = name; e->message = message; + e->need_free = false; } int sd_bus_error_is_set(const sd_bus_error *e) { if (!e) return 0; - return e->name || e->message || e->need_free; + return !!e->name; } int sd_bus_error_has_name(const sd_bus_error *e, const char *name) { diff --git a/src/libsystemd-bus/bus-error.h b/src/libsystemd-bus/bus-error.h index f49e6c7398..c6e072eab4 100644 --- a/src/libsystemd-bus/bus-error.h +++ b/src/libsystemd-bus/bus-error.h @@ -25,3 +25,5 @@ int bus_error_to_errno(const sd_bus_error *e); int bus_error_from_errno(sd_bus_error *e, int error); + +bool bus_error_is_dirty(sd_bus_error *e); diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index a1bae4d1a7..5f3dbdb75d 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -447,9 +447,7 @@ int sd_bus_message_new_method_error( sd_bus_message *t; int r; - if (!e) - return -EINVAL; - if (!e->name) + if (!sd_bus_error_is_set(e)) return -EINVAL; if (!m) return -EINVAL; diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 70288ee131..c5cbb5682d 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -1131,7 +1131,7 @@ int sd_bus_send_with_reply_and_block( return -EINVAL; if (!m->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL) return -EINVAL; - if (sd_bus_error_is_set(error)) + if (sd_bus_error_is_dirty(error)) return -EINVAL; r = sd_bus_send(bus, m, &serial); diff --git a/src/libsystemd-bus/sd-bus.h b/src/libsystemd-bus/sd-bus.h index d655f05dc3..d892562b5f 100644 --- a/src/libsystemd-bus/sd-bus.h +++ b/src/libsystemd-bus/sd-bus.h @@ -131,9 +131,9 @@ int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid); int sd_bus_add_match(sd_bus *bus, const char *match); int sd_bus_remove_match(sd_bus *bus, const char *match); -/* Error objects */ +/* Error structures */ -#define SD_BUS_ERROR_INIT (NULL, NULL, false) +#define SD_BUS_ERROR_INIT (NULL, NULL, 0) void sd_bus_error_free(sd_bus_error *e); int sd_bus_error_set(sd_bus_error *e, const char *name, const char *format, ...); |