chiark / gitweb /
bus: use C99 struct construction for error initializers
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Apr 2013 11:11:26 +0000 (13:11 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Apr 2013 11:12:11 +0000 (13:12 +0200)
That way we can allocate an error struct on-the-fly while calling a
function. Nice!

src/libsystemd-bus/sd-bus.c
src/libsystemd-bus/test-bus-chat.c
src/libsystemd-bus/test-bus-server.c
src/systemd/sd-bus.h

index 8c5b9da91d831394754db57b68375bee7482ed96..0b71f3ea5462a95e210abb2b1a6236aa23c903e5 100644 (file)
@@ -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);
 
index 459d39fdee5070664fc6f1103b621c2d6a9debff..6f711c1d8658a426d8da142f99f9e00ff9d40962 100644 (file)
@@ -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;
index a594ce3157f529e9690a1a7f1fe7dc4fc0238fce..a9772624f22ee11cb697b5f51775f7a158a5cef2 100644 (file)
@@ -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);
index fd87de0813aed7bcaa8233a3aa96e348edc4a86f..27226a92ed9c2b4d942529cdb13da2972093ca70 100644 (file)
@@ -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, ...);