]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: don't fall back to immediate shutdown silently if we cannot schedule one
authorMike Yuan <me@yhndnzj.com>
Thu, 31 Oct 2024 14:45:15 +0000 (15:45 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 31 Oct 2024 14:45:40 +0000 (15:45 +0100)
The previous behavior of systemctl --when= seems absurd, i.e.
if we fail to schedule shutdown in the future it's performed
immediately. Let's instead hard fail, which also removes the need
of specializing on certain errnos (preparation for later commits).

src/systemctl/systemctl-start-special.c

index 00dd05bff7775bffa05b53fbb47cb30a1c31d720..5fff5d4f1867b21863076470b81972319c638b38 100644 (file)
@@ -201,14 +201,17 @@ int verb_start_special(int argc, char *argv[], void *userdata) {
                 case ACTION_KEXEC:
                 case ACTION_HALT:
                 case ACTION_SOFT_REBOOT:
-                        if (arg_when == 0)
+                        if (arg_when == 0) {
                                 r = logind_reboot(a);
-                        else
+                                if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS))
+                                        /* The latter indicates that the requested operation requires auth,
+                                         * is not supported or already in progress, in which cases we ignore the error. */
+                                        return r;
+                        } else {
                                 r = logind_schedule_shutdown(a);
-                        if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS))
-                                /* The latter indicates that the requested operation requires auth,
-                                 * is not supported or already in progress, in which cases we ignore the error. */
-                                return r;
+                                if (r != -ENOSYS)
+                                        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