Fix QEMU hanging when boot.sh --test output is piped#378
Merged
Conversation
boot.sh --test now redirects stdin from /dev/null before exec'ing QEMU, so QEMU's -nographic serial setup never calls tcsetattr() on a real terminal. When the caller pipes stdout (e.g., through tee) or wraps boot.sh with timeout(1), QEMU runs in a process group that is not the terminal's foreground group; a tcsetattr() call then receives SIGTTOU and stops the process (state Tl), producing no output. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Thank @linesight for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When I ran
devtools/test-modules.shfrom my terminal, it printed "Booting QEMU for testing" and then produced no further output. Inps aux, QEMU was stuck in stateTl(stopped).Root cause:
-nographicmakes QEMU calltcsetattr()to put the terminal in raw mode for serial input. That's fine when QEMU runs in the foreground, buttest-modules.shpipes stdout throughtee, andtimeout(1)moves the child into its own process group (so it can kill the whole group on timeout). Since that group isn't the terminal's foreground group,tcsetattr()receivesSIGTTOUand the kernel stops QEMU before it prints anything.The fix: redirect stdin from
/dev/nullinboot.sh --testmode. The guest never needs keyboard input during automated testing, so this is always safe, and it prevents QEMU from ever touching a real terminal.CI never hit this because GitHub Actions runners don't have a TTY —
tcsetattr()fails silently withENOTTYinside a container.Tested both
test-modules.sh(33 passed, 0 failed) and interactiveboot.shto confirm the fix doesn't break anything.Summary by cubic
Prevents QEMU from hanging in test mode when output is piped by redirecting stdin from
/dev/null. This avoidsSIGTTOUfromtcsetattr()under-nographicso tests print output and complete.boot.sh --test, exec QEMU with< /dev/nullto avoid touching the real TTY.teeandtimeout(1);devtools/test-modules.shpasses, and interactiveboot.shis unchanged.Written for commit 37cf3aa. Summary will update on new commits. Review in cubic