Repository navigation
fix(stdio): adopt read_stdin_record for all plain-ReadFile console stdin readers (head/install/xargs/read_all_stdin) - #1458
Merged
Conversation
…ugh read_stdin_record (winux#1450 family) Class-complete adoption of file_io::read_stdin_record() (introduced by #1454) for every command that reads console stdin via plain ReadFile: - head: output_first_records stdin fast path (head -n/-c live stdin); a zero-byte read at ^D-empty ends head early, like GNU head on a tty (VEOF). The helper is not armed on the FILE_TYPE_PIPE face, so the #1289/R2 short-read pipe contract is byte-identical. - install: copy_stdin_to_dest (install /dev/stdin dest); ^D-empty ends the copy, matching GNU reading stdin until EOF on a tty (uutils#12407). - xargs: read_confirmation CONIN$ arm (the Windows /dev/tty answer, #1320); ^D at line start ends the answer read and lands on the loud Fatal path, matching tty EOF under GNU xargs -p. - file_io: read_all_stdin switches from the std::cin loop to a read_stdin_record loop (named by #1454 notes as needing adoption), so envsubst and the base32/base64/basenc/tac "-" faces plus /dev/stdin aliases observe VEOF on a cooked console. Pipes end with ReadFile FALSE + ERROR_BROKEN_PIPE (not TRUE+0); std::cin mapped that to clean EOF and GNU read(2) returns 0, so the loop classifies ERROR_BROKEN_PIPE / ERROR_NO_DATA / ERROR_HANDLE_EOF as EOF and keeps everything else a genuine error (the std::cin.bad() analog). Left untouched (audited, classified in the sweep report): - pipe/fifo handles (head output_pipe_*, read_handle_to_string), by-size file reads (cpio/patch/tsort/xxd/locate/look), child pipes (diff3), raw key-event pagers (less/more/pager) - different mechanism by design. - dd (class D, documented): on a Unix tty dd does end at ^D-empty, so adoption would be defensible, but dd's fixed-block contract (if=/skip=/ count=/conv=, PeekNamedPipe probe, broken-pipe mapping) is judged too load-bearing for this mechanical sweep; recorded as follow-up material. - CRT-mediated faces (std::cin/fread stdin: sort/uniq/col/cksum/cmp/tsort/ xxd/md5sum*/sha*sum/tr/top) - the helper is handle-shaped; recorded as the follow-up family. Evidence (matched Release builds, base f4f8d8a vs this branch): - ConPTY battery 9/9 adopt-PASS; base red exactly on the six adopted faces (head/envsubst/base64/tac/tac /dev/stdin/install hang swallowing the sentinel line; xargs -p takes ^D+zz as a "No" answer) and green on both guard cells (cat #1454, xargs answer "y"). - Pipe/file battery 12/12 byte-identical (incl. dd guard, xargs CRT arm, uniq CRT face); battery run 1 caught the ERROR_BROKEN_PIPE regression before it shipped - fixed and re-proven on the final binary. - ctest 3462 tests: base 99% / 8 pre-existing failures (NUL #1333, #1288, cygdrive form); adopt failure set == base set, no new failures. GNU anchor: termios VEOF line discipline (canonical tty), as established in #1454 / f4f8d8a. Stacked on #1454 (fix/1450-cat-veof) - not mergeable before it.
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.
Stacked dependency: requires #1454 (
fix/1450-cat-veof) to merge first — this branch sits directly on it (537a60f → f4f8d8a → this). The diff-vs-main shown below includes #1454's cat commit; the new diff is exactly 4 files, +46/−14.Class-complete adoption of
file_io::read_stdin_record()(the VEOF-simulation helper from #1454) across every command that reads console stdin via plain ReadFile, per the no-whack-a-mole directive: one helper, no per-command logic. The helper arms only on a line-input console handle and falls through to plainReadFileeverywhere else, so non-console faces are byte-identical by construction (and proven identical below).Adopted (4 sites)
head.cpp:348output_first_recordshead -n/-clive stdininstall.cpp:368copy_stdin_to_destinstall /dev/stdin destxargs.cpp:1112read_confirmation(CONIN$ arm)xargs -p/dev/tty answerfile_io.cppmread_all_stdin-, /dev/stdin aliases viaread_all_fileOne subtlety surfaced by the pipe battery: pipes end with ReadFile FALSE +
ERROR_BROKEN_PIPE, not TRUE+0 — std::cin mapped that to clean EOF and GNUread(2)returns 0, soread_all_stdinclassifiesERROR_BROKEN_PIPE/ERROR_NO_DATA/ERROR_HANDLE_EOFas EOF; anything else stays a genuine error (thestd::cin.bad()analog). The other three sites already broke on FALSE (cat/head convention).Audited and left untouched (classified in the report)
output_pipe_*(fifo operands head 行/记录模式在 FIFO 操作数上不截断:tee 写者全量打印,部分写者零输出(字节模式、stdin 面、cat 均正常) #1442),read_handle_to_string, diff3 child pipe; by-size file reads (cpio/patch/tsort/xxd/locate/look); raw key-event pagers (less/more/pager).dd.cpp:1030for a follow-up. Verified untouched A/B.fread(stdin)(md5sum*/sha*sum/tr/top) — swapping those to raw ReadFile is not byte-neutral on pipes (CRT text-mode CRLF translation) and needs its own design.Evidence (matched Release builds: base f4f8d8a vs this branch)
tac /dev/stdin/install all hang swallowing the sentinel line;xargs -ptreats^D+sentinel as a "No" answer rc=0) and green on both guards (cat fix(cat): deliver VEOF (^D) on the cooked console face #1454; xargs answer "y"). ^D delivered as raw 0x04; cells use the ^D-then-sentinel shape from the fix(cat): deliver VEOF (^D) on the cooked console face #1454 evidence run (cooked conhost delivers a record only on Enter).tac /dev/stdin, uniq (CRT face),dd bs=4 count=1guard,xargs -ppiped answer (CRT arm), base64 FILE stdin.GNU anchor: termios VEOF line discipline (canonical tty), as established in #1454 / f4f8d8a.
Fixes the head/install/read_all_stdin/xargs follow-ups named in the #1454 known-limits note (except dd, documented above).