]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shutdown: don't freeze() if not executed by pid1
authorMike Yuan <me@yhndnzj.com>
Wed, 15 May 2024 15:02:02 +0000 (23:02 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 03:39:29 +0000 (11:39 +0800)
src/shutdown/shutdown.c

index 49f986f8c8a3cbd3d5aa074f595c51c80a35c096..1d41b9f8e43d72e285b08849777cebd45533576b 100644 (file)
@@ -377,8 +377,12 @@ int main(int argc, char *argv[]) {
         log_set_prohibit_ipc(true);
         log_parse_environment();
 
-        if (getpid_cached() == 1)
-                log_set_always_reopen_console(true);
+        if (getpid_cached() != 1) {
+                log_error("Not executed by init (PID 1). Refusing to operate.");
+                return EXIT_FAILURE;
+        }
+
+        log_set_always_reopen_console(true);
 
         r = parse_argv(argc, argv);
         if (r < 0)
@@ -388,11 +392,6 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        if (getpid_cached() != 1) {
-                r = log_error_errno(SYNTHETIC_ERRNO(EPERM), "Not executed by init (PID 1).");
-                goto error;
-        }
-
         if (streq(arg_verb, "reboot"))
                 cmd = RB_AUTOBOOT;
         else if (streq(arg_verb, "poweroff"))
@@ -667,7 +666,7 @@ int main(int argc, char *argv[]) {
 
         r = log_error_errno(errno, "Failed to invoke reboot(): %m");
 
-  error:
+error:
         log_struct_errno(LOG_EMERG, r,
                          LOG_MESSAGE("Critical error while doing system shutdown: %m"),
                          "MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_ERROR_STR);