Repository navigation
WIP: fix numbered-fd heredoc delivery to external children (#2270) - #2271
Merged
Merged
Conversation
Refs #2270 `./reader.sh 3<<EOF` left the child's fd 3 unbound (reads failed EBADF): in spawn_external_process's own-redirects loop a HereDoc / HereString entry fell into the write bucket (its kind is in none of the input exclusions), so the loop "opened" the delimiter word as an output file in the cwd and delivered THAT descriptor instead of the body. GNU's contract is fd-number-agnostic: do_redirection_internal's r_reading_until / r_deblank_reading_until / r_reading_string arm calls here_document_to_fd (redir.c:423), which places the body in a temporary file, and dup2's the resulting descriptor onto the redirector (redir.c:1065-1072) — the same installation for fd 0, fd 3, or any other number. Mirror that contract in the one spawn-side loop: a heredoc / here-string entry now materializes the canonical body text (external_fd_heredoc_input — the ladder the /dev/fd operand and <&N source faces already use) into a carrier file via write_process_substitution_temp (registered as an adhoc carrier, the route seam's precedent), and the ordinary input arm below opens it and delivers it through the same __RUBASH_FD_* env keys and Unix pre_exec pins as a file input redirect. fd 0 keeps its existing apply_external_stdin_redirect path; no parallel numbered-fd implementation is added. Last-wins ordering across repeated redirects on one fd follows from the loop's list order (do_redirections, redir.c:237). Regression pins in tests/issue2270_external_numbered_fd_heredoc_ regressions.rs (10 pins): << and <<- on fd 3, fd 4, here-string, last-wins, quoted-delimiter literal body, the child's exit code after reading the body to EOF, no stray delimiter file, plus fd 0 and plain 3<file controls. Expectations byte-verified against GNU bash 5.3.20 via probes/probe-2270.sh. The <<- pin also needs the numbered-fd strip-tabs lexer fix (PR #2269 / #2265) and stays red for that reason alone on a tree without it. Local verification: cargo check only (compile rationing); pins are pending the collector's batch run.
caomengxuan666
marked this pull request as ready for review
October 30, 2026 18:08
Resolve external_inner.rs against #2253/#2263: keep the #2235 stash lookup ahead of the #2270 heredoc arm (a heredoc entry still classifies as write at lookup time, so it can never claim a stash — matching the dup replay, which kind-skips heredocs; a same-fd stash belongs to an earlier plain entry and the heredoc's later stamp preserves last-wins). Semantic check: diff vs master is exactly this PR's change set. Refs #2270
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.
WIP: Refs #2270
Problem
./reader.sh 3<<EOFleft the external child's fd 3 unbound — readsfailed EBADF — while the same body on fd 0 and a plain
3<filebothworked. In
spawn_external_process's own-redirects loop, aHereDoc / HereString entry fell into the write bucket (its kind is
in none of the input exclusions), so the loop "opened" the
delimiter word as an output file in the cwd and delivered that
descriptor instead of the body.
Fix (one installation contract, by mechanism)
GNU's contract is fd-number-agnostic:
do_redirection_internal'sr_reading_until / r_deblank_reading_until / r_reading_string arm
calls
here_document_to_fd(redir.c:423), which places the body ina temporary file, and dup2's the resulting descriptor onto the
redirector (redir.c:1065-1072).
The loop now special-cases only the SOURCE of the binding: a
heredoc / here-string entry materializes the canonical body text
(
external_fd_heredoc_input— the ladder the /dev/fd operand and<&Nsource faces already use) into a carrier file viawrite_process_substitution_temp(registered as an adhoc carrier,the route seam's precedent), and the ordinary input arm opens it
and delivers it through the same
__RUBASH_FD_*env keys and Unixpre_exec pins as a file input redirect. No parallel numbered-fd
implementation; fd 0 keeps its existing
apply_external_stdin_redirectpath; in-process faces (builtins /functions) keep binding the same body as an fd-table text entry.
Last-wins across repeated redirects on one fd follows from the
loop's list order (do_redirections, redir.c:237).
Pins
tests/issue2270_external_numbered_fd_heredoc_regressions.rs,10 pins:
<<and<<-on fd 3, fd 4, here-string, last-wins,quoted-delimiter literal body, child exit code after reading the
body to EOF, no stray delimiter file, plus fd 0 and plain
3<filecontrols. Expectations byte-verified against GNU bash5.3.20 via
probes/probe-2270.sh(cluster workdir).Verification split (compile rationing)
cargo checkclean; oracle probe run (all faces).comparison.
<<-pin also needs the numbered-fd strip-tabslexer fix (PR WIP: fix(lexer): deblank flag for fd-prefixed <<- heredocs (#2265) #2269 / t0000 test-lib 自检子测试 6 条分歧(--immediate/--run/--invert-exit-code 族,#2035 验收残面) #2265); on a tree without it that one pin
is red for the lexer's reason alone.
into
apply_external_fd_delivery; whichever lands second mustcarry this heredoc arm into the helper mechanically.