diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-05 13:11:26 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-05 13:12:11 +0200 |
commit | c784c5ce777f16ee56086a072dc1466639bc9eff (patch) | |
tree | 4d092bb8f0d6a8386f29f10ccc9174be47a15723 /src | |
parent | 1e64bbc15671db861c811bdf63014eee826a6eca (diff) |
bus: use C99 struct construction for error initializers
That way we can allocate an error struct on-the-fly while calling a
function. Nice!
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/sd-bus.c | 6 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-chat.c | 10 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-server.c | 9 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 4 |
4 files changed, 16 insertions, 13 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index 8c5b9da91d..0b71f3ea54 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -1592,7 +1592,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) { r = sd_bus_message_append(reply, "s", sd_id128_to_string(id, sid)); } else { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_INIT; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_error_set(&error, "org.freedesktop.DBus.Error.UnknownMethod", @@ -1612,7 +1612,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) { } static int process_object(sd_bus *bus, sd_bus_message *m) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_INIT; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; struct object_callback *c; int r; @@ -1857,7 +1857,7 @@ static int process_running(sd_bus *bus, sd_bus_message **ret) { if (m->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_INIT; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_error_set(&error, "org.freedesktop.DBus.Error.UnknownObject", "Unknown object '%s'.", m->path); diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c index 459d39fdee..6f711c1d86 100644 --- a/src/libsystemd-bus/test-bus-chat.c +++ b/src/libsystemd-bus/test-bus-chat.c @@ -251,9 +251,11 @@ static int server(sd_bus *bus) { } } else if (sd_bus_message_is_method_call(m, NULL, NULL)) { - const sd_bus_error e = SD_BUS_ERROR_INIT_CONST("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method."); - r = sd_bus_message_new_method_error(bus, m, &e, &reply); + r = sd_bus_message_new_method_error( + bus, m, + &SD_BUS_ERROR_MAKE("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method."), + &reply); if (r < 0) { log_error("Failed to allocate return: %s", strerror(-r)); goto fail; @@ -287,7 +289,7 @@ fail: static void* client1(void*p) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; sd_bus *bus = NULL; - sd_bus_error error = SD_BUS_ERROR_INIT; + sd_bus_error error = SD_BUS_ERROR_NULL; const char *hello; int r; int pp[2] = { -1, -1 }; @@ -413,7 +415,7 @@ static int quit_callback(sd_bus *b, int ret, sd_bus_message *m, void *userdata) static void* client2(void*p) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; sd_bus *bus = NULL; - sd_bus_error error = SD_BUS_ERROR_INIT; + sd_bus_error error = SD_BUS_ERROR_NULL; bool quit = false; const char *mid; int r; diff --git a/src/libsystemd-bus/test-bus-server.c b/src/libsystemd-bus/test-bus-server.c index a594ce3157..a9772624f2 100644 --- a/src/libsystemd-bus/test-bus-server.c +++ b/src/libsystemd-bus/test-bus-server.c @@ -96,9 +96,10 @@ static void *server(void *p) { quit = true; } else if (sd_bus_message_is_method_call(m, NULL, NULL)) { - const sd_bus_error e = SD_BUS_ERROR_INIT_CONST("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method."); - - r = sd_bus_message_new_method_error(bus, m, &e, &reply); + r = sd_bus_message_new_method_error( + bus, m, + &SD_BUS_ERROR_MAKE("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method."), + &reply); if (r < 0) { log_error("Failed to allocate return: %s", strerror(-r)); goto fail; @@ -128,7 +129,7 @@ fail: static int client(struct context *c) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL; _cleanup_bus_unref_ sd_bus *bus = NULL; - sd_bus_error error = SD_BUS_ERROR_INIT; + sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert_se(sd_bus_new(&bus) >= 0); diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index fd87de0813..27226a92ed 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -162,8 +162,8 @@ int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid); /* Error structures */ -#define SD_BUS_ERROR_INIT {NULL, NULL, 0} -#define SD_BUS_ERROR_INIT_CONST(name, message) {(name), (message), 0} +#define SD_BUS_ERROR_NULL ((sd_bus_error) {NULL, NULL, 0}) +#define SD_BUS_ERROR_MAKE(name, message) ((sd_bus_error) {(name), (message), 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, ...); |