sd-varlink: suppress one log message when callback already successfully enqueued...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 Oct 2024 19:02:54 +0000 (04:02 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Oct 2024 21:58:35 +0000 (22:58 +0100)
Follow-up for d2ebf5cc1d59e29139f06efaa3a9b2c184cdaa25.

The detailed error response is already logged, hence not necessary to
log again with the errno converted from the error response, which typically
less informative, e.g.
===
varlink-26-26: Setting state idle-server
varlink-26-26: Received message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"service":""}}
varlink-26-26: Changing state idle-server → processing-method
varlink-26-26: Sending message: {"error":"io.systemd.UserDatabase.BadService","parameters":{}}
varlink-26-26: Changing state processing-method → processed-method
varlink-26-26: Callback for io.systemd.UserDatabase.GetUserRecord returned error: Invalid request descriptor
varlink-26-26: Changing state processed-method → idle-server
varlink-26-26: Got POLLHUP from socket.
===

src/libsystemd/sd-varlink/sd-varlink.c

index 73fcc71f867d16f99d9511ed3caa7abd0dc3675f..9c9160fd4e41cf36b6baf07de6b6174ba9f093d4 100644 (file)
@@ -1386,17 +1386,15 @@ static int varlink_dispatch_method(sd_varlink *v) {
 
                 if (!invalid) {
                         r = callback(v, parameters, flags, v->userdata);
-                        if (r < 0) {
+                        if (r < 0 && VARLINK_STATE_WANTS_REPLY(v->state)) {
                                 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 (VARLINK_STATE_WANTS_REPLY(v->state)) {
-                                        r = sd_varlink_error_errno(v, r);
-                                        /* If we didn't manage to enqueue an error response, then fail the connection completely. */
-                                        if (r < 0 && VARLINK_STATE_WANTS_REPLY(v->state))
-                                                goto fail;
-                                }
+                                r = sd_varlink_error_errno(v, r);
+                                /* If we didn't manage to enqueue an error response, then fail the connection completely. */
+                                if (r < 0 && VARLINK_STATE_WANTS_REPLY(v->state))
+                                        goto fail;
                         }
                 }
         } else if (VARLINK_STATE_WANTS_REPLY(v->state)) {