summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudwig Nussel <ludwig.nussel@suse.de>2021-12-08 12:48:35 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-12-09 15:07:40 +0100
commita9c3cc8db02dc36d41b17d0bbf1e02500046e4ce (patch)
tree3ce0350f6942404129edd6fc82fcd99b93fc6b60
parentb55093ce8884ee4fc72f28c6fd5e39897e921e21 (diff)
downloadsystemd-a9c3cc8db02dc36d41b17d0bbf1e02500046e4ce.tar.gz
systemctl: add shutdown --show option
Shows the scheduled shutdown action and time if there's one.
-rw-r--r--man/shutdown.xml7
-rw-r--r--src/systemctl/systemctl-compat-shutdown.c9
-rw-r--r--src/systemctl/systemctl-logind.c35
-rw-r--r--src/systemctl/systemctl-logind.h1
-rw-r--r--src/systemctl/systemctl.c4
-rw-r--r--src/systemctl/systemctl.h1
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,
};