summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--man/systemd.xml13
-rw-r--r--src/shutdown/shutdown.c22
-rw-r--r--src/systemctl/systemctl-start-special.c16
4 files changed, 47 insertions, 7 deletions
diff --git a/TODO b/TODO
index 8c52f65b55..163f66f152 100644
--- a/TODO
+++ b/TODO
@@ -130,6 +130,9 @@ Deprecations and removals:
Features:
+* Clean up "reboot argument" handling, i.e. set it through some IPC service
+ instead of directly via /run/, so that it can be sensible set remotely.
+
* userdb: add concept for user "aliases", to cover for cases where you can log
in under the name lennart@somenetworkfsserver, and it would automatically
generate a local user, and from the one both names can be used to allow
diff --git a/man/systemd.xml b/man/systemd.xml
index abfcc499f0..df0027886c 100644
--- a/man/systemd.xml
+++ b/man/systemd.xml
@@ -1257,6 +1257,19 @@
details.</para>
<xi:include href="version-info.xml" xpointer="v256"/></listitem>
+
+ <listitem><para>An <varname>X_SYSTEMD_SHUTDOWN=…</varname> message will be sent out very shortly before
+ the system shuts down. The value is one of the strings <literal>reboot</literal>,
+ <literal>halt</literal>, <literal>poweroff</literal>, <literal>kexec</literal> and indicates which kind
+ of shutdown is being executed.</para>
+
+ <xi:include href="version-info.xml" xpointer="v256"/></listitem>
+
+ <listitem><para>An <varname>X_SYSTEMD_REBOOT_PARAMETER=…</varname> message will also be sent out very
+ shortly before the system shuts down. Its value is the reboot argument as configured with
+ <command>systemctl --reboot-argument=…</command>.</para>
+
+ <xi:include href="version-info.xml" xpointer="v256"/></listitem>
</itemizedlist>
<para>Note that these extension fields are sent in addition to the regular <literal>READY=1</literal> and
diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c
index b709078afe..1ddda00941 100644
--- a/src/shutdown/shutdown.c
+++ b/src/shutdown/shutdown.c
@@ -333,6 +333,26 @@ static void init_watchdog(void) {
}
}
+static void notify_supervisor(void) {
+ /* Notify VMM/container manager of the desired mode of reboot and the boot parameter */
+ _cleanup_free_ char *reboot_parameter = NULL;
+ int r;
+
+ r = read_reboot_parameter(&reboot_parameter);
+ if (r < 0 && r != -ENOENT)
+ log_debug_errno(r, "Failed to read reboot parameter, ignoring: %m");
+
+ if (reboot_parameter)
+ (void) sd_notifyf(/* unset_environment= */ false,
+ "X_SYSTEMD_SHUTDOWN=%s\n"
+ "X_SYSTEMD_REBOOT_PARAMETER=%s",
+ arg_verb, reboot_parameter);
+ else
+ (void) sd_notifyf(/* unset_environment= */ false,
+ "X_SYSTEMD_SHUTDOWN=%s",
+ arg_verb);
+}
+
int main(int argc, char *argv[]) {
static const char* const dirs[] = {
SYSTEM_SHUTDOWN_PATH,
@@ -589,6 +609,8 @@ int main(int argc, char *argv[]) {
if (!in_container)
sync_with_progress();
+ notify_supervisor();
+
if (streq(arg_verb, "exit")) {
if (in_container) {
log_info("Exiting container.");
diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c
index d486b406da..4b99d0c629 100644
--- a/src/systemctl/systemctl-start-special.c
+++ b/src/systemctl/systemctl-start-special.c
@@ -155,14 +155,16 @@ int verb_start_special(int argc, char *argv[], void *userdata) {
return r;
}
- if (a == ACTION_REBOOT) {
- if (arg_reboot_argument) {
- r = update_reboot_parameter_and_warn(arg_reboot_argument, false);
- if (r < 0)
- return r;
- }
+ if (arg_reboot_argument && IN_SET(a, ACTION_HALT, ACTION_POWEROFF, ACTION_REBOOT, ACTION_KEXEC)) {
+ /* If we are going through an action that involves systemd-shutdown, let's set the reboot
+ * parameter, even if it's not a regular reboot. After all we nowadays send the string to
+ * our supervisor via sd_notify() too. */
+ r = update_reboot_parameter_and_warn(arg_reboot_argument, /* keep= */ false);
+ if (r < 0)
+ return r;
+ }
- } else if (a == ACTION_KEXEC) {
+ if (a == ACTION_KEXEC) {
r = load_kexec_kernel();
if (r < 0 && arg_force >= 1)
log_notice("Failed to load kexec kernel, continuing without.");