From: Lennart Poettering Date: Tue, 12 Dec 2017 22:26:36 +0000 (+0100) Subject: sd-bus: propagate handling errors for Hello method reply directly X-Git-Tag: v237~139^2~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b057498a5275c8734b7e430f7d9b1dd13243c98a;p=thirdparty%2Fsystemd.git sd-bus: propagate handling errors for Hello method reply directly 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. --- diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 9daa758a1c4..a99c993dd10 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -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); }