diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-03-05 23:27:44 +0800 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-03-14 19:21:11 +0800 |
commit | 1433e1f998465b7acf472c73d58c14e7e2eb3f13 (patch) | |
tree | 89ffc9ccc34b5a6b8f56069106e78b4e1bd9b5d6 /src/systemctl/systemctl-start-special.c | |
parent | 92b00e867844948bdf559758739343c4308570c0 (diff) | |
download | systemd-1433e1f998465b7acf472c73d58c14e7e2eb3f13.tar.gz |
systemctl: add option --when for scheduled shutdown
Pass an empty string or "cancel" will cancel the action.
Pass "show" will show the scheduled actions.
Replaces #17258
Diffstat (limited to 'src/systemctl/systemctl-start-special.c')
-rw-r--r-- | src/systemctl/systemctl-start-special.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c index 1c50adff6e..93432953b0 100644 --- a/src/systemctl/systemctl-start-special.c +++ b/src/systemctl/systemctl-start-special.c @@ -197,22 +197,33 @@ int verb_start_special(int argc, char *argv[], void *userdata) { ACTION_POWEROFF, ACTION_REBOOT, ACTION_KEXEC, - ACTION_HALT, - ACTION_SUSPEND, - ACTION_HIBERNATE, - ACTION_HYBRID_SLEEP, - ACTION_SUSPEND_THEN_HIBERNATE)) { - - r = logind_reboot(a); - if (r >= 0) - return r; - if (IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) - /* Requested operation requires auth, is not supported or already in progress */ + ACTION_HALT)) { + + if (arg_when == 0) + r = logind_reboot(a); + else if (arg_when != USEC_INFINITY) + r = logind_schedule_shutdown(a); + else /* arg_when == USEC_INFINITY */ + r = logind_cancel_shutdown(); + 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; /* 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 * for this, as logind's shutdown operations are always non-blocking. */ + arg_no_block = true; + + } else if (IN_SET(a, + ACTION_SUSPEND, + ACTION_HIBERNATE, + ACTION_HYBRID_SLEEP, + ACTION_SUSPEND_THEN_HIBERNATE)) { + + r = logind_reboot(a); + if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) + return r; arg_no_block = true; |