Skip to content

shutdown: preserve console graphics mode across the exitrd handoff - #43671

Merged
yuwata merged 1 commit into
systemd:mainfrom
birkskyum:upstream/preserve-shutdown-console
Sep 23, 2026
Merged

yuwata merged 1 commit into
systemd:mainfrom
birkskyum:upstream/preserve-shutdown-console

Conversation

@birkskyum

@birkskyum birkskyum commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve the current console graphics mode when systemd-shutdown reopens /dev/console before executing /shutdown in the exitrd.

make_console_stdio() currently calls reset_dev_console_fd() with switch_to_text=true. During the exitrd handoff, that can replace a graphical shutdown splash retained by Plymouth with the text console. Allow the internal helper's caller to choose whether to switch modes, and pass false at this one shutdown call site. The core manager reexecution and crash-shell callers continue to pass true.

If executing /shutdown fails, restore text before reporting the saved execution error and continuing with fallback shutdown. Also restore text before the fatal shutdown message and freeze(). This does not disable logging, alter watchdog behavior or add a hardware-specific condition. A console already in text mode remains in text mode.

Validation

  • Based on main at 9457f81485bfe8e09d45c0376fe02ebce7c15872, fetched again on 7 September.
  • AArch64 build: systemd-shutdown.standalone, systemd and test-console-stdio.
  • meson test -C build -v test-terminal-util test-umount: passed.
  • The separate VT test is unsafe, nonparallel and requires explicit opt-in, the required capabilities and an already-owned inactive controlling VT. It does not allocate or disallocate VTs. The caller's terminal session remains alive while the child tests mode preservation and text reset.
  • The VT case passed in Docker's ARM64 Linux VM on an inactive VT supplied by openvt --wait, without --switch or --force. The active VT stayed unchanged and the test VT was in text mode afterward.
  • Negative controls forcing text for every call and never restoring text each fail with visible mode assertions. Parent cleanup restores text after the child aborts.
  • No opt-in, insufficient privileges, and separately injected namespace, bind-mount and mode-setting permission failures skip without changing the active VT or leaving graphics mode behind.
  • The equivalent successful-handoff change against v261.2 was previously tested on a Lenovo Yoga Slim 7x running Omarchy/Arch Linux ARM. The terminal flash disappeared, and reboot continued to disk unlock and the desktop.

The full test suite, a complete boot of current-main systemd and an injected PID-1 exitrd execution failure have not been tested. The physical reboot observation is for the v261.2 backport, not the main-based binary.

@github-actions github-actions Bot added util-lib tests shutdown please-review PR is ready for (re-)review by a maintainer labels Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Claude review failed (workflow run)

Reviewed the switch_to_text plumbing in make_console_stdio() and the new virtual-console test.

Completed lenses: resource lifetimes and concurrency; security and robustness; architecture, API design and compatibility; coding style and maintainability; tests and regression coverage; plus two domain lenses (Linux VT/console semantics and splash interoperability, test-environment isolation and host side effects). Incomplete: the correctness and memory safety lens exceeded its time budget and was stopped, so its findings are missing; its area is partly covered by the other lenses. All confirmed candidates were re-checked by independent validators.

Verified separately: all three production callers of make_console_stdio() were updated for the new signature, so there is no build break.

Must fix

  • src/shutdown/shutdown.c:648 - passing switch_to_text=false leaves the console in KD_GRAPHICS with nothing restoring KD_TEXT, so the execv() failure message, the "Unable to finalize remaining..." error and the LOG_EMERG message before freeze() are never rendered; after the earlier SIGKILL sweep the preserved mode often has no splash owner redrawing it.
  • src/test/test-terminal-util.c:384 - the skip guard only covers opening /dev/tty0 and VT_OPENQRY, while the test also needs CAP_SYS_ADMIN and CAP_SYS_TTY_CONFIG, so restricted environments hard-fail instead of skipping; the intended privilege skip at line 416 is unreachable. VT_OPENQRY also does not reserve the VT, and the mount namespace does not isolate the VT device.
  • src/test/test-terminal-util.c:418 - the VT restore and vt_disallocate() run before the fork result is checked, so they mutate a queried-but-unowned VT even when no child ran; and because each teardown step is an aborting assertion there is no unwind path, leaking the VT (possibly in KD_GRAPHICS).

Suggestions

  • src/test/test-terminal-util.c:401 - after make_console_stdio() the child's stderr is the unattached VT that the parent then clears and disallocates, so an in-child assertion failure loses its diagnostic and surfaces only as a generic -EPROTO.
  • src/test/test-terminal-util.c:378 - the case mutates global machine state but the binary is not marked 'type' : 'unsafe' in src/test/meson.build, unlike other host-side-effecting tests.

Nits

  • src/test/test-terminal-util.c:394 - pidref_safe_fork() continuation lines align with neither the opening parenthesis nor the double-indent rule in docs/CODING_STYLE.md.
  • src/test/test-terminal-util.c:389 - mode serves both as the saved value the parent restores and as the child's scratch readback buffer.

Not raised as inline comments: the repository agent guidance in the base revision asks that a review-confirmation banner be present as the first two lines of README.md when source files are modified, and this PR modifies source files without it. That is a process/documentation step for the human author rather than a code defect, so it is noted here only.

Comment thread src/shutdown/shutdown.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
Comment thread src/test/test-terminal-util.c Resolved
@birkskyum
birkskyum force-pushed the upstream/preserve-shutdown-console branch from 2633d9e to 9ff9082 Compare September 7, 2026 00:48
@poettering poettering added good-to-merge/after-next-release and removed please-review PR is ready for (re-)review by a maintainer labels Sep 7, 2026
@poettering poettering added this to the v263 milestone Sep 7, 2026
@bluca bluca added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/after-next-release claude-review labels Sep 22, 2026
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.
@bluca
bluca force-pushed the upstream/preserve-shutdown-console branch from 9ff9082 to 00712c3 Compare September 22, 2026 22:30
@yuwata
yuwata merged commit ef3e0ff into systemd:main Sep 23, 2026
66 of 78 checks passed
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants