]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: fix halt -f 22445/head
authorLudwig Nussel <ludwig.nussel@suse.de>
Wed, 9 Feb 2022 09:39:16 +0000 (10:39 +0100)
committerLudwig Nussel <ludwig.nussel@suse.de>
Mon, 14 Feb 2022 08:35:12 +0000 (09:35 +0100)
Commit adefc8789b always asks logind for shutdown first. So I broke halt
-f which is supposed to issue a direct syscall in that case.

src/systemctl/systemctl-compat-halt.c

index a7d3ffadf421d7d3807fdbd677c9e1e2098ba197..c8d745592fd4c0a60fdb6670ee7255e7816d1d01 100644 (file)
@@ -12,6 +12,7 @@
 #include "systemctl-compat-halt.h"
 #include "systemctl-compat-telinit.h"
 #include "systemctl-logind.h"
+#include "systemctl-start-unit.h"
 #include "systemctl-util.h"
 #include "systemctl.h"
 #include "terminal-util.h"
@@ -144,30 +145,32 @@ int halt_parse_argv(int argc, char *argv[]) {
 int halt_main(void) {
         int r;
 
-        /* always try logind first */
-        if (arg_when > 0)
-                r = logind_schedule_shutdown();
-        else {
-                r = logind_check_inhibitors(arg_action);
-                if (r < 0)
+        if (arg_force == 0) {
+                /* always try logind first */
+                if (arg_when > 0)
+                        r = logind_schedule_shutdown();
+                else {
+                        r = logind_check_inhibitors(arg_action);
+                        if (r < 0)
+                                return r;
+
+                        r = logind_reboot(arg_action);
+                }
+                if (r >= 0)
+                        return r;
+                if (IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS))
+                        /* Requested operation requires auth, is not supported on the local system or already in
+                         * progress */
                         return r;
+                /* 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;
 
-                r = logind_reboot(arg_action);
+                if (!arg_dry_run)
+                        return start_with_fallback();
         }
-        if (r >= 0)
-                return r;
-        if (IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS))
-                /* Requested operation requires auth, is not supported on the local system or already in
-                 * progress */
-                return r;
-        /* 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;
-
-        if (!arg_dry_run && !arg_force)
-                return start_with_fallback();
 
         if (geteuid() != 0) {
                 (void) must_be_root();