Repository navigation
fix(read): serve fd-0 self-dups through the ordinary fd-0 transports - #975
Merged
Merged
Conversation
…938) Residual face of the #700/#701 fd family: `read x </dev/stdin`, `read x <&0` (and the `/dev/fd/0`, `/proc/self/fd/0`, `<&0-`, `-u 0` forms) inside a pipeline group stage saw EOF where the pipe held data. GNU redir.c:1128 do_redirection_internal gates a descriptor dup's whole action — the dup2 AND the r_move_input close — on `redir_fd != redirector`, so every fd-0 self-dup is a complete no-op that leaves fd 0 bound exactly as it was; `-u 0` likewise names fd 0 itself (read.def:294). Rubash instead served those reads from the fd-table-only descriptor path, which has no endpoint for a stage's FUNCTION_STDIN mirror and returned None (EOF, rc 1, empty variable). - read_io.rs read_input_for_command: `read -u 0` falls through to the ordinary fd-0 read chain; an input redirect on fd 0 resolving to descriptor 0 (any `<&0`-family word or /dev-stdin alias) is skipped wholesale as the GNU no-op it is. - read_builtin.rs read_fd_is_available: the move-close check only fires when the redirector differs from the source (the close lives inside the same redir.c:1128 guard); fd 0 is a valid read descriptor whenever the table recorded no explicit close — the F_GETFD rule sh_validfd applies (read.def:377-381), matching validate_builtin_dup_source's stdio-always-open rule. - read_builtin.rs read_timeout_zero_status: `-u 0 -t 0` polls fd 0 like the no-`-u` arm (read.def:539-562 select() on the one descriptor). Verified: ticket repro byte-identical to the stated GNU output (devstdin/dup0/plain=SIN, gotf=FILE, empty stderr, rc 0); regression- catalog issue-700 output flips diverges->must-match (manifest promoted); old-vs-new binary differential on issue-699..704/714/723/726 is byte-identical apart from the intended issue-700 fix. Targeted suites green: issue700/701/275/276/277/279/280/714 read family, fd0 cursor, 429/436/615/586/591/647 stdin transports, redirect/parser suites (1 environmental failure in issue647 — the test embeds a backslashed winuxcmd true.exe path unquoted; identical failure on base master). EOF discipline preserved: empty pipe under a self-dup still returns rc 1 with the empty record assigned. Fixes #938 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Summary
readbuiltin hangs forever on/dev/stdin#700/readbuiltin: empty from/dev/fd/N, and rc=0 at EOF under compound/fd redirection (while readoff-by-one) #701 fd family:read x </dev/stdin,read x <&0(plus/dev/fd/0,/proc/self/fd/0, the<&0-move form, and-u 0) inside a pipeline group stage saw EOF where fd 0 held the pipe data.redir.c:1128do_redirection_internalruns a descriptor dup's whole action — thedup2and ther_move_inputclose — only whenredir_fd != redirector, so every fd-0 self-dup is a complete no-op;-u 0likewise names fd 0 itself (read.def:294). Rubash served those reads from the fd-table-only descriptor path, which has no endpoint for a pipeline stage's FUNCTION_STDIN mirror and returned EOF.read_input_for_commandnow lets-u 0and any fd-0 self-dup redirect fall through to the ordinary fd-0 transports (fd-table endpoints → FUNCTION_STDIN mirror → inherited process stdin), matching a barereadexactly.read_fd_is_availablegates the move-close check onredirector != source(the close is inside the sameredir.c:1128guard) and treats fd 0 as a valid descriptor unless the table recorded an explicit close — theF_GETFDrulesh_validfdapplies (read.def:377-381).read_timeout_zero_statuspolls fd 0 for-u 0 -t 0like the no--uarm.scripts/regression-catalog: issue-700 promoteddiverges→must-match(the read builtin reads empty via </dev/stdin / <&0 in pipeline group context (residual of the #700/#701 fd family) #938 residual face now matches); newtests/issue938_read_fd0_selfdup.rspins the family as a script file (the-cshape binds the inherited-stdin transport and masks the bug).Test plan
devstdin=[SIN],dup0=[SIN],plain=[SIN],gotf=[FILE], empty stderr, rc 0)pipe=[SIN],dup0=[DUP])cargo test: issue700/701 (fd family pinned, no regress), issue275/276/277/279/280/714 read family, fd0 cursor transport, issue429/436/615/586/591 stdin transports, issue324/325/330/353/355/359/362/368/370/385/392/438/508/514/518/525/535/575/699/773/804/817/826/844/846/861 redirect/procsub family, parser_redirection_tests — all greenwhile read <&0/while read </dev/stdiniterate the pipe; sequential<&0then bare reads share the cursor;{ read <&0; } < filereads the bound file;-u0 -t2reads with rc 0; empty pipe under a self-dup still fails rc 1 with the empty record assignedissue647::function_call_file_redirect_survives_external_spawnembeds a backslashed winuxcmdtrue.exepath unquoted in the generated script — any POSIX shell strips the backslashes; identical failure reproduces on base master binary, unrelated to this changeFixes #938
Generated with Devin