]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine: adjust operation callback logic for varlink
authorIvan Kruglov <mail@ikruglov.com>
Wed, 6 Nov 2024 13:31:29 +0000 (14:31 +0100)
committerIvan Kruglov <mail@ikruglov.com>
Mon, 6 Jan 2025 13:41:49 +0000 (14:41 +0100)
This is to simplyfy varlink callback. There is no use of this logic atm.
So, no harm.

src/machine/operation.c

index 7d7bfa50627efdac735515d35e77a8e5fde87f02..00b9e092499a4c6813efe26f52598f9d5a66fb3c 100644 (file)
@@ -46,10 +46,12 @@ static int operation_done(sd_event_source *s, const siginfo_t *si, void *userdat
         if (r < 0)
                 log_debug_errno(r, "Operation failed: %m");
 
-        /* If a completion routine (o->done) is set for this operation, call it. It sends a response, but can return an error in which case it expect us to reply.
-         * Otherwise, the default action is to simply return an error on failure or an empty success message on success. */
-
         if (o->message) {
+                /* If o->done set, call it. It sends a response, but can return
+                 * an error in which case it expect this code to reply.
+                 * If o->done is not set, the default action is to simply return
+                 * an error on failure or an empty success message on success.*/
+
                 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
                 if (o->done)
                         r = o->done(o, r, &error);
@@ -68,13 +70,16 @@ static int operation_done(sd_event_source *s, const siginfo_t *si, void *userdat
                                 log_error_errno(r, "Failed to reply to dbus message: %m");
                 }
         } else if (o->link) {
-                if (o->done)
-                        r = o->done(o, r, /* error = */ NULL);
+                /* If o->done set, call it. Unlike o->message case above, this
+                 * code expect o->done to reply in all cases.
+                 * If o->done is not set, the default action is to simply return
+                 * an error on failure or an empty success message on success.*/
 
-                if (r < 0)
+                if (o->done)
+                        (void) o->done(o, r, /* error = */ NULL);
+                else if (r < 0)
                         (void) sd_varlink_error_errno(o->link, r);
-                else if (!o->done)
-                        /* when o->done set it's responsible for sending reply in a happy-path case */
+                else
                         (void) sd_varlink_reply(o->link, NULL);
         } else
                 assert_not_reached();