Commit fbfa72b0 authored by Lennart Poettering's avatar Lennart Poettering

bus: introduce bus_error_is_dirty() independently of sd_bus_error_is_set()

parent 80a46c73
......@@ -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) {
......
......@@ -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);
......@@ -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;
......
......@@ -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);
......
......@@ -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, ...);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment