Skip to content

Atomic print and re-print desc on status, flush before reboot#485

Merged
troglobit merged 1 commit intomasterfrom
console-output-fixes
Apr 8, 2026
Merged

Atomic print and re-print desc on status, flush before reboot#485
troglobit merged 1 commit intomasterfrom
console-output-fixes

Conversation

@troglobit
Copy link
Copy Markdown
Collaborator

Refactor print() to emit description + final status in a single call to cprintf(), preventing kernel messages from splitting the two parts.

For two-phase print(-1,...) + print_result() sequences used by, e.g., run_interactive(), save the last description and re-print it before the [ OK ] / [FAIL] output so the status is never left stranded on a blank line when command output or kernel messages have scrolled away the original description.

Finally, add print_exit() which drains the console output buffer with tcdrain(2) and resets ANSI SGR attributes + cursor visibility before the kernel takes back the console on reboot/halt, preventing escape code leakage into bootloader or early-kernel output.

Refactor print() to emit description + final status in a single call to
cprintf(), preventing kernel messages from splitting the two parts.

For two-phase print(-1,...) + print_result() sequences used by, e.g.,
run_interactive, save the last description and re-print it before the
[ OK ] / [FAIL] output so the status is never left stranded on a blank
line when command output or kernel messages have scrolled away the
original description.

Finally, add print_exit() which drains the console output buffer with
tcdrain(2) and resets ANSI SGR attributes + cursor visibility before the
kernel takes back the console on reboot/halt, preventing escape code
leakage into bootloader or early-kernel output.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the progress/status printing path to avoid kernel/command output interleaving with the final status marker, improves two-phase “pending + final result” output by re-printing the last description, and adds a shutdown-time console cleanup/drain helper before reboot/halt.

Changes:

  • Refactor print() to build description + final status into a single cprintf() call for more atomic console writes.
  • Persist the last pending description and re-print it on print_result() so [ OK ]/[FAIL] isn’t left detached.
  • Add print_exit() and invoke it before reboot/poweroff/halt to drain output and reset console escape state.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/helpers.c Implements atomic final status printing, saves/reprints last description, adds print_exit()
src/helpers.h Exposes print_exit() prototype
src/sig.c Calls print_exit() before reboot/poweroff/halt

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@troglobit troglobit merged commit 8f6c616 into master Apr 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants