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.
This commit is contained in:
Lennart Poettering 2017-12-12 23:26:36 +01:00
parent b33652fe91
commit b057498a52

View 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);
}