]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: propagate handling errors for Hello method reply directly
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Dec 2017 22:26:36 +0000 (23:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2018 12:55:08 +0000 (13:55 +0100)
Currently, when sd-bus is used to issue a method call, and we get a
reply and the specified reply handler fails, we log this locally at
debug priority and proceed. The idea is that a bad server-side reply
should not be fatal for the program, except when the developer
explicitly terminates the event loop.

The reply to the initial Hello() method call we issue when joining a bus
should not be handled like that however. Instead, propagate the error
immediately, as anything that is wrong with the Hello() reply should be
considered a fatal connection problem.

src/libsystemd/sd-bus/sd-bus.c

index 9daa758a1c4b5f775262620d2d73a65afbb8e868..a99c993dd1008ae4cfc3f060246cff2576c1d32e 100644 (file)
@@ -2059,6 +2059,7 @@ static int process_timeout(sd_bus *bus) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message* m = NULL;
         struct reply_callback *c;
         sd_bus_slot *slot;
+        bool is_hello;
         usec_t n;
         int r;
 
@@ -2094,6 +2095,8 @@ static int process_timeout(sd_bus *bus) {
 
         bus->iteration_counter++;
 
+        is_hello = bus->state == BUS_HELLO && c->callback == hello_callback;
+
         bus->current_message = m;
         bus->current_slot = sd_bus_slot_ref(slot);
         bus->current_handler = c->callback;
@@ -2111,6 +2114,11 @@ static int process_timeout(sd_bus *bus) {
 
         sd_bus_slot_unref(slot);
 
+        /* When this is the hello message and it failed, then make sure to propagate the error up, don't just log and
+         * ignore the callback handler's return value. */
+        if (is_hello)
+                return r;
+
         return bus_maybe_reply_error(m, r, &error_buffer);
 }
 
@@ -2140,6 +2148,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
         _cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
         struct reply_callback *c;
         sd_bus_slot *slot;
+        bool is_hello;
         int r;
 
         assert(bus);
@@ -2193,6 +2202,8 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
                 c->timeout = 0;
         }
 
+        is_hello = bus->state == BUS_HELLO && c->callback == hello_callback;
+
         bus->current_slot = sd_bus_slot_ref(slot);
         bus->current_handler = c->callback;
         bus->current_userdata = slot->userdata;
@@ -2208,6 +2219,11 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
 
         sd_bus_slot_unref(slot);
 
+        /* When this is the hello message and it timed out, then make sure to propagate the error up, don't just log
+         * and ignore the callback handler's return value. */
+        if (is_hello)
+                return r;
+
         return bus_maybe_reply_error(m, r, &error_buffer);
 }