varlink: never turn method call handler errors into connection errors

Let's make sure method call handlers failing will result in that very
method call failing but not the whole connection. We mostly got that
right, except for "oneway" calls where the method reply is supposed to
be eaten up, but wasn't. Fix that.
This commit is contained in:
Lennart Poettering 2023-11-23 18:15:14 +01:00
parent 6bcc12325b
commit c931c871aa

View file

@ -1350,9 +1350,7 @@ static int varlink_dispatch_method(Varlink *v) {
varlink_log_errno(v, r, "Callback for %s returned error: %m", method);
/* We got an error back from the callback. Propagate it to the client if the method call remains unanswered. */
if (v->state == VARLINK_PROCESSED_METHOD)
r = 0; /* already processed */
else if (!FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) {
if (v->state != VARLINK_PROCESSED_METHOD && !FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) {
r = varlink_error_errno(v, r);
if (r < 0)
return r;
@ -1363,8 +1361,7 @@ static int varlink_dispatch_method(Varlink *v) {
r = varlink_errorb(v, VARLINK_ERROR_METHOD_NOT_FOUND, JSON_BUILD_OBJECT(JSON_BUILD_PAIR("method", JSON_BUILD_STRING(method))));
if (r < 0)
return r;
} else
r = 0;
}
switch (v->state) {
@ -1386,7 +1383,7 @@ static int varlink_dispatch_method(Varlink *v) {
assert_not_reached();
}
return r;
return 1;
invalid:
r = -EINVAL;