From 2a3a5288cb2f4e4434b8b69ab43e71a5b6d42cca Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Wed, 9 Feb 2022 10:39:16 +0100 Subject: [PATCH] systemctl: fix halt -f 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 | 45 ++++++++++++++------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/systemctl/systemctl-compat-halt.c b/src/systemctl/systemctl-compat-halt.c index a7d3ffadf42..c8d745592fd 100644 --- a/src/systemctl/systemctl-compat-halt.c +++ b/src/systemctl/systemctl-compat-halt.c @@ -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(); -- 2.47.3