fix: run interactive pty in raw mode so stdout is not truncated - #845
Open
SomSamantray wants to merge 3 commits into
Open
fix: run interactive pty in raw mode so stdout is not truncated#845SomSamantray wants to merge 3 commits into
SomSamantray wants to merge 3 commits into
Conversation
The pty slave allocated for interactive containers was left in canonical mode, whose line discipline buffers output and causes large writes to be truncated at 1024 bytes (reported in apple/container#1148). A process writing more than 1024 bytes to stdout and exiting loses the buffered tail because the canonical-mode tty holds it waiting for a line terminator. Configure the slave with the existing Terminal.setraw() recipe (cfmakeraw plus OPOST preserved) before dup3'ing it onto stdio, so output passes through without truncation while newline-to-CRLF translation is kept. Add a regression test asserting the termios flags: a fresh pty slave is canonical, and setraw() clears ICANON while preserving OPOST.
Unify the ICANON and OPOST assertions through one flag-membership helper operating on a tcflag_t field, instead of re-inlining the same bit-mask idiom with different shapes.
cfmakeraw clears OPOST but leaves ONLCR set; re-adding OPOST in Terminal.setraw() restores newline-to-CRLF output translation. Lock both flags so the raw-mode recipe's output behavior is pinned by the test.
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.
Interactive containers (
container run --interactiveon apple/container) truncated stdout at 1024 bytes when output went to a terminal or file: the guest pty slave was left in canonical mode, whose line discipline buffers large writes, so a process writing more than 1024 bytes and exiting lost the buffered tail.The pty slave is now put into raw mode before it is wired onto the container's stdio, using the existing
Terminal.setraw()recipe (cfmakeraw with OPOST/ONLCR preserved so CRLF output translation is kept). A regression test asserts the raw-mode termios flags (ICANON cleared, OPOST and ONLCR preserved).Session-settled decisions carried from planning: raw-mode fix on the pty slave (user-approved, over buffering increases or userland read loops); OPOST preservation after cfmakeraw (user-approved, matching
Terminal.setraw()).Related: apple/container#1148