Skip to content

fix: run interactive pty in raw mode so stdout is not truncated - #845

Open
SomSamantray wants to merge 3 commits into
apple:mainfrom
SomSamantray:fix/pty-raw-mode-interactive-stdout
Open

fix: run interactive pty in raw mode so stdout is not truncated#845
SomSamantray wants to merge 3 commits into
apple:mainfrom
SomSamantray:fix/pty-raw-mode-interactive-stdout

Conversation

@SomSamantray

Copy link
Copy Markdown

Interactive containers (container run --interactive on 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

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.
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.

1 participant