summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-03-05 23:27:44 +0800
committerMike Yuan <me@yhndnzj.com>2023-03-14 19:21:11 +0800
commit1433e1f998465b7acf472c73d58c14e7e2eb3f13 (patch)
tree89ffc9ccc34b5a6b8f56069106e78b4e1bd9b5d6 /src/systemctl/systemctl.c
parent92b00e867844948bdf559758739343c4308570c0 (diff)
downloadsystemd-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.c')
-rw-r--r--src/systemctl/systemctl.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 862edada08..1a5beabc72 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -323,6 +323,8 @@ static int systemctl_help(void) {
" --mkdir Create directory before mounting, if missing\n"
" --marked Restart/reload previously marked units\n"
" --drop-in=NAME Edit unit files using the specified drop-in file name\n"
+ " --when=TIME Schedule halt/power-off/reboot/kexec action after\n"
+ " a certain timestamp\n"
"\nSee the %2$s for details.\n",
program_invocation_short_name,
link,
@@ -447,6 +449,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_MARKED,
ARG_NO_WARN,
ARG_DROP_IN,
+ ARG_WHEN,
};
static const struct option options[] = {
@@ -511,6 +514,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "mkdir", no_argument, NULL, ARG_MKDIR },
{ "marked", no_argument, NULL, ARG_MARKED },
{ "drop-in", required_argument, NULL, ARG_DROP_IN },
+ { "when", required_argument, NULL, ARG_WHEN },
{}
};
@@ -975,6 +979,30 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
arg_drop_in = optarg;
break;
+ case ARG_WHEN:
+ if (streq(optarg, "show")) {
+ r = logind_show_shutdown();
+ if (r < 0 && r != -ENODATA)
+ return r;
+
+ return 0;
+ }
+
+ if (STR_IN_SET(optarg, "", "cancel")) {
+ arg_when = USEC_INFINITY;
+ break;
+ }
+
+ r = parse_timestamp(optarg, &arg_when);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse --when= argument '%s': %m", optarg);
+
+ if (!timestamp_is_set(arg_when))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid timestamp '%s' specified for --when=.", optarg);
+
+ break;
+
case '.':
/* Output an error mimicking getopt, and print a hint afterwards */
log_error("%s: invalid option -- '.'", program_invocation_name);