summaryrefslogtreecommitdiffstats
path: root/src/systemctl
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-10-31 15:45:15 +0100
committerMike Yuan <me@yhndnzj.com>2024-10-31 15:45:40 +0100
commit249bb7f89433934b025f25e444358b39db3beb92 (patch)
treea4e76982c5c234fdc4424eaad4ffe6a9ae2dc2eb /src/systemctl
parentlogind-dbus: return appropriate errno for unexpected errors (diff)
downloadsystemd-249bb7f89433934b025f25e444358b39db3beb92.tar.xz
systemd-249bb7f89433934b025f25e444358b39db3beb92.zip
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).
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-start-special.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c
index 00dd05bff7..5fff5d4f18 100644
--- a/src/systemctl/systemctl-start-special.c
+++ b/src/systemctl/systemctl-start-special.c
@@ -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