ryantimwilson / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
6f381c
From d36295d7c1b110d150b7af6e3354c28af4c4884d Mon Sep 17 00:00:00 2001
6f381c
From: David Tardon <dtardon@redhat.com>
6f381c
Date: Mon, 30 Jan 2023 14:27:24 +0100
6f381c
Subject: [PATCH] systemctl: reintroduce the original halt_main()
6f381c
6f381c
RHEL-only
6f381c
6f381c
Related: #2053273
6f381c
---
6f381c
 src/systemctl/systemctl.c | 59 +++++++++++++++++++++++++++++++++++++++
6f381c
 1 file changed, 59 insertions(+)
6f381c
6f381c
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
6f381c
index 199f736f7f..a26e4a913a 100644
6f381c
--- a/src/systemctl/systemctl.c
6f381c
+++ b/src/systemctl/systemctl.c
6f381c
@@ -8655,6 +8655,65 @@ static int logind_schedule_shutdown(void) {
6f381c
 #endif
6f381c
 }
6f381c
 
6f381c
+static int halt_main_old(void) {
6f381c
+        int r;
6f381c
+
6f381c
+        r = logind_check_inhibitors(arg_action);
6f381c
+        if (r < 0)
6f381c
+                return r;
6f381c
+
6f381c
+        if (arg_when > 0)
6f381c
+                return logind_schedule_shutdown();
6f381c
+
6f381c
+        if (geteuid() != 0) {
6f381c
+                if (arg_dry_run || arg_force > 0) {
6f381c
+                        (void) must_be_root();
6f381c
+                        return -EPERM;
6f381c
+                }
6f381c
+
6f381c
+                /* Try logind if we are a normal user and no special
6f381c
+                 * mode applies. Maybe PolicyKit allows us to shutdown
6f381c
+                 * the machine. */
6f381c
+                if (IN_SET(arg_action, ACTION_POWEROFF, ACTION_REBOOT, ACTION_HALT)) {
6f381c
+                        r = logind_reboot(arg_action);
6f381c
+                        if (r >= 0)
6f381c
+                                return r;
6f381c
+                        if (IN_SET(r, -EOPNOTSUPP, -EINPROGRESS))
6f381c
+                                /* requested operation is not
6f381c
+                                 * supported on the local system or
6f381c
+                                 * already in progress */
6f381c
+                                return r;
6f381c
+                        /* on all other errors, try low-level operation */
6f381c
+                }
6f381c
+        }
6f381c
+
6f381c
+        /* In order to minimize the difference between operation with and
6f381c
+         * without logind, we explicitly enable non-blocking mode for this,
6f381c
+         * as logind's shutdown operations are always non-blocking. */
6f381c
+        arg_no_block = true;
6f381c
+
6f381c
+        if (!arg_dry_run && !arg_force)
6f381c
+                return start_with_fallback();
6f381c
+
6f381c
+        assert(geteuid() == 0);
6f381c
+
6f381c
+        if (!arg_no_wtmp) {
6f381c
+                if (sd_booted() > 0)
6f381c
+                        log_debug("Not writing utmp record, assuming that systemd-update-utmp is used.");
6f381c
+                else {
6f381c
+                        r = utmp_put_shutdown();
6f381c
+                        if (r < 0)
6f381c
+                                log_warning_errno(r, "Failed to write utmp record: %m");
6f381c
+                }
6f381c
+        }
6f381c
+
6f381c
+        if (arg_dry_run)
6f381c
+                return 0;
6f381c
+
6f381c
+        r = halt_now(arg_action);
6f381c
+        return log_error_errno(r, "Failed to reboot: %m");
6f381c
+}
6f381c
+
6f381c
 static int halt_main(void) {
6f381c
         int r;
6f381c