diff options
-rw-r--r-- | man/shutdown.xml | 7 | ||||
-rw-r--r-- | src/systemctl/systemctl-compat-shutdown.c | 9 | ||||
-rw-r--r-- | src/systemctl/systemctl-logind.c | 35 | ||||
-rw-r--r-- | src/systemctl/systemctl-logind.h | 1 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 4 | ||||
-rw-r--r-- | src/systemctl/systemctl.h | 1 |
6 files changed, 56 insertions, 1 deletions
diff --git a/man/shutdown.xml b/man/shutdown.xml index f29010f6b6..b07736ee68 100644 --- a/man/shutdown.xml +++ b/man/shutdown.xml @@ -125,6 +125,13 @@ <literal>now</literal>.</para></listitem> </varlistentry> + <varlistentry> + <term><option>--show</option></term> + + <listitem><para>Show a pending shutdown action and time if + there is any.</para></listitem> + </varlistentry> + </variablelist> </refsect1> diff --git a/src/systemctl/systemctl-compat-shutdown.c b/src/systemctl/systemctl-compat-shutdown.c index 5e613e2aa2..6571802f95 100644 --- a/src/systemctl/systemctl-compat-shutdown.c +++ b/src/systemctl/systemctl-compat-shutdown.c @@ -28,6 +28,7 @@ static int shutdown_help(void) { " -k Don't halt/power-off/reboot, just send warnings\n" " --no-wall Don't send wall message before halt/power-off/reboot\n" " -c Cancel a pending shutdown\n" + " --show Show pending shutdown\n" "\nSee the %s for details.\n", program_invocation_short_name, ansi_highlight(), @@ -40,7 +41,8 @@ static int shutdown_help(void) { int shutdown_parse_argv(int argc, char *argv[]) { enum { ARG_HELP = 0x100, - ARG_NO_WALL + ARG_NO_WALL, + ARG_SHOW }; static const struct option options[] = { @@ -50,6 +52,7 @@ int shutdown_parse_argv(int argc, char *argv[]) { { "reboot", no_argument, NULL, 'r' }, { "kexec", no_argument, NULL, 'K' }, /* not documented extension */ { "no-wall", no_argument, NULL, ARG_NO_WALL }, + { "show", no_argument, NULL, ARG_SHOW }, {} }; @@ -108,6 +111,10 @@ int shutdown_parse_argv(int argc, char *argv[]) { arg_action = ACTION_CANCEL_SHUTDOWN; break; + case ARG_SHOW: + arg_action = ACTION_SHOW_SHUTDOWN; + break; + case '?': return -EINVAL; diff --git a/src/systemctl/systemctl-logind.c b/src/systemctl/systemctl-logind.c index b1c0e13f2c..2d2043f177 100644 --- a/src/systemctl/systemctl-logind.c +++ b/src/systemctl/systemctl-logind.c @@ -372,6 +372,41 @@ int logind_cancel_shutdown(void) { #endif } +int logind_show_shutdown(void) { +#if ENABLE_LOGIND + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + sd_bus *bus; + const char *action = NULL; + uint64_t elapse; + int r; + + r = acquire_bus(BUS_FULL, &bus); + if (r < 0) + return r; + + r = bus_get_property(bus, bus_login_mgr, "ScheduledShutdown", &error, &reply, "(st)"); + if (r < 0) + return log_error_errno(r, "Failed to query scheduled shutdown: %s", bus_error_message(&error, r)); + + r = sd_bus_message_read(reply, "(st)", &action, &elapse); + if (r < 0) + return r; + + if (isempty(action)) + return log_error_errno(SYNTHETIC_ERRNO(ENODATA), "No scheduled shutdown."); + + log_info("%s scheduled for %s, use 'shutdown -c' to cancel.", + action, + FORMAT_TIMESTAMP_STYLE(arg_when, arg_timestamp_style)); + + return 0; +#else + return log_error_errno(SYNTHETIC_ERRNO(ENOSYS), + "Not compiled with logind support, cannot show scheduled shutdowns."); +#endif +} + int help_boot_loader_entry(void) { #if ENABLE_LOGIND _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; diff --git a/src/systemctl/systemctl-logind.h b/src/systemctl/systemctl-logind.h index 144056b939..6e73cb7625 100644 --- a/src/systemctl/systemctl-logind.h +++ b/src/systemctl/systemctl-logind.h @@ -14,5 +14,6 @@ int prepare_boot_loader_entry(void); int logind_schedule_shutdown(void); int logind_cancel_shutdown(void); +int logind_show_shutdown(void); int help_boot_loader_entry(void); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 6f76a63165..9031e685ea 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1169,6 +1169,10 @@ static int run(int argc, char *argv[]) { r = logind_cancel_shutdown(); break; + case ACTION_SHOW_SHUTDOWN: + r = logind_show_shutdown(); + break; + case ACTION_RUNLEVEL: r = runlevel_main(); break; diff --git a/src/systemctl/systemctl.h b/src/systemctl/systemctl.h index 8199ae9e0d..d6b9d7495c 100644 --- a/src/systemctl/systemctl.h +++ b/src/systemctl/systemctl.h @@ -32,6 +32,7 @@ enum action { ACTION_RUNLEVEL, ACTION_TELINIT, ACTION_CANCEL_SHUTDOWN, + ACTION_SHOW_SHUTDOWN, _ACTION_MAX, _ACTION_INVALID = -EINVAL, }; |