systemctl: don't fall back to immediate shutdown silently if we cannot schedule one

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).
This commit is contained in:
Mike Yuan
2024-10-31 15:45:40 +01:00
parent 57d8134d45
commit 249bb7f894
+9 -6
View 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