From 041a66b8432c73cbc36bd7addc9178e23df67209 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 11 Oct 2023 16:59:59 +0200 Subject: [PATCH] varlink: didn't generate a varlink error reply if a failed method call handler already did It might happen that a method call handler already generated an error reply and then still propagated the error back to the varlink logic. Let's not try to generate a 2nd reply from that error code then, but simply proceed without. This simplifies handling of errors in method call handlers, because they can uniformly return errno-style error codes, and only if they want return a full Varlink errror. --- src/shared/varlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 8f643e27b0f..118ede7e05d 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -1330,7 +1330,9 @@ static int varlink_dispatch_method(Varlink *v) { log_debug_errno(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 (!FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) { + if (v->state == VARLINK_PROCESSED_METHOD) + r = 0; /* already processed */ + else if (!FLAGS_SET(flags, VARLINK_METHOD_ONEWAY)) { r = varlink_error_errno(v, r); if (r < 0) return r;