shutdown: preserve console graphics mode across the exitrd handoff

make_console_stdio() forces KD_TEXT while reopening /dev/console. When
systemd-shutdown enters the exitrd, this can expose the text console over
a retained graphical shutdown splash.

Let callers choose whether to switch to text mode, and preserve the mode
for the exitrd handoff. Keep the existing text-mode behavior for manager
reexecution and the crash shell. Restore text mode if executing /shutdown
fails and before reporting a fatal error and freezing.

Add an unsafe, nonparallel virtual-console regression test requiring
explicit opt-in and an already-owned inactive VT in a disposable VM.
Check graphics preservation and text restoration through a private
/dev/console bind mount, retain stderr diagnostics, and restore the saved
mode in the parent even if the child fails.

(cherry picked from commit ef3e0ff7bb)
This commit is contained in:
Birk Skyum
2026-10-16 11:36:31 +01:00
committed by Luca Boccassi
parent 1946818513
commit bfba34d783
7 changed files with 117 additions and 7 deletions
+2 -2
View File
@@ -1046,7 +1046,7 @@ int lock_dev_console(void) {
return TAKE_FD(fd);
}
int make_console_stdio(void) {
int make_console_stdio(bool switch_to_text) {
int fd, r;
/* Make /dev/console the controlling terminal and stdin/stdout/stderr, if we can. If we can't use
@@ -1062,7 +1062,7 @@ int make_console_stdio(void) {
return log_error_errno(r, "Failed to make /dev/null stdin/stdout/stderr: %m");
} else {
reset_dev_console_fd(fd, /* switch_to_text= */ true);
reset_dev_console_fd(fd, switch_to_text);
r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
if (r < 0)
+1 -1
View File
@@ -112,7 +112,7 @@ int vtnr_from_tty(const char *tty);
void reset_dev_console_fd(int fd, bool switch_to_text);
int lock_dev_console(void);
int make_console_stdio(void);
int make_console_stdio(bool switch_to_text);
int getenv_columns(void);
int fd_columns(int fd);