chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:54 +0000 (07:49 +0200)
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/libelogind/sd-bus/sd-bus.c

index cd9b010997121c8a96fe1e881ff5943993d4c3b7..8a465b9da6b7c858e4361b11c67f39942579986d 100644 (file)
@@ -2074,6 +2074,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;
 
@@ -2109,6 +2110,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;
@@ -2126,6 +2129,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);
 }
 
@@ -2155,6 +2163,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);
@@ -2208,6 +2217,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;
@@ -2223,6 +2234,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);
 }