]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: never turn method call handler errors into connection errors
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Nov 2023 17:15:14 +0000 (18:15 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 Dec 2023 14:25:46 +0000 (15:25 +0100)
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.

src/shared/varlink.c

index 47528b3e70aaaf25ba36add2989ef107a6040861..3f022e88bd304e5dfc54d1a524dff76e066edc70 100644 (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;