Blob Blame History Raw
From f975f1cc748929942188ae1490cf8480f8a64877 Mon Sep 17 00:00:00 2001
From: Anita Zhang <the.anitazha@gmail.com>
Date: Thu, 4 Mar 2021 19:56:16 -0800
Subject: [PATCH 1/2] shutdown: set always_reopen_console

Back in v232 systemd-shutdown would log to /dev/console. However after
the addition of always_reopen_console (v233) it would log to STDERR.
This caused some debugging issues as container systemd-shutdown logs
weren't being logged to console as the arg `--log-target=console` suggested.

Since it appears that always_reopen_console was intended for pid1, set
it in systemd-shutdown as well so logs will go to /dev/console.
---
 src/shutdown/shutdown.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c
index 0d07865542e..c1fdc885afb 100644
--- a/src/shutdown/shutdown.c
+++ b/src/shutdown/shutdown.c
@@ -322,6 +322,9 @@ int main(int argc, char *argv[]) {
         log_set_prohibit_ipc(true);
         log_parse_environment();
 
+        if (getpid_cached() == 1)
+                log_set_always_reopen_console(true);
+
         r = parse_argv(argc, argv);
         if (r < 0)
                 goto error;

From 016f36ae72611210d6517b37429bfbdc26c5e31c Mon Sep 17 00:00:00 2001
From: Anita Zhang <the.anitazha@gmail.com>
Date: Thu, 4 Mar 2021 20:00:05 -0800
Subject: [PATCH 2/2] shutdown: log on container exit

---
 src/shutdown/shutdown.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c
index c1fdc885afb..06b6618ff4c 100644
--- a/src/shutdown/shutdown.c
+++ b/src/shutdown/shutdown.c
@@ -559,8 +559,10 @@ int main(int argc, char *argv[]) {
                 sync_with_progress();
 
         if (streq(arg_verb, "exit")) {
-                if (in_container)
+                if (in_container) {
+                        log_info("Exiting container.");
                         return arg_exit_code;
+                }
 
                 cmd = RB_POWER_OFF; /* We cannot exit() on the host, fallback on another method. */
         }