]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: make sure "reboot", "suspend" and friends are always asynchronous
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Sep 2017 14:07:11 +0000 (16:07 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 4 Oct 2017 18:56:24 +0000 (20:56 +0200)
Currently, "systemctl reboot" behaves differently in setups with and
without logind. If logind is used (which is probably the more common
case) the operation is asynchronous, and otherwise synchronous (though
subject to --no-block in this case). Let's clean this up, and always
expose the same behaviour, regardless if logind is used or not: let's
always make it asynchronous.

It might make sense to add a "--block" mode in a future PR that makes
these operations synchronous, but this requires non-trivial work in
logind, and is outside of the scope of this change.

See: #6479

src/systemctl/systemctl.c

index 2a385bf35035711182037922d375c770655414f0..dd0ebff179364199e3bcfdf5ad125de1f61534aa 100644 (file)
@@ -3585,8 +3585,16 @@ static int start_special(int argc, char *argv[], void *userdata) {
                                 /* requested operation is not supported or already in progress */
                                 return r;
 
-                        /* On all other errors, try low-level operation */
-                }
+                        /* On all other errors, try low-level operation. In order to minimize the difference between
+                         * operation with and without logind, we explicitly enable non-blocking mode for this, as
+                         * logind's shutdown operations are always non-blocking. */
+
+                        arg_no_block = true;
+
+                } else if (IN_SET(a, ACTION_EXIT, ACTION_KEXEC))
+                        /* Since exit/kexec are so close in behaviour to power-off/reboot, let's also make them
+                         * asynchronous, in order to not confuse the user needlessly with unexpected behaviour. */
+                        arg_no_block = true;
 
                 r = start_unit(argc, argv, userdata);
         }