Repository navigation
fix(builtins): source /dev/stdin reads the command's own stdin redirect (rubash#1642) - #1685
arookieofc wants to merge 1 commit into
Conversation
…ct (rubash#1642) GNU redir.c do_redirections binds fd 0 before the builtin runs, so opening /dev/stdin reads the redirect. Rubash's /dev/stdin arm fell through to the pipeline buffer or the process stdin instead: with a here-string, heredoc, or '< file' redirect it blocked on a live stdin, or silently read EOF when stdin was redirected (the piped form worked only because the pipe IS the process stdin). The arm now checks first whether the source command carries its own fd-0 stdin redirect, and if so sources the redirect's text via stdin_string_for_command_mut (the same effective-stdin path other builtins use). Bare commands in pipelines keep the existing FUNCTION_STDIN / process-stdin path untouched, and an explicit redirect still wins over a pipe. A failed redirect never reaches here: the simple-command dispatch reports it first (rc 1, source never runs). Regression tests: tests/issue1642_source_dev_stdin_redirect_regressions.rs (7 tests: here-string, file, heredoc, pipe control, redirect-wins-over- pipe, /dev/fd/0 alias, missing-redirect fails fast).
…6-10-26) Tests-only incorporation per the fd-source dual-route ruling (~/workspace/collab-pr-review/REPORT.md §3.2): the slice takes the route, and the two test shapes only the single-issue PR #1685 carried are pinned in the slice's regression file before #1685 is closed as incorporated: - explicit fd-0 redirection wins over piped process stdin (GNU: redir.c binds fd 0 before the builtin runs) - /dev/fd/0 alias spelling of the same binding No production code change; the slice's read-only stdin ladder already resolves both shapes (redirect_cmd before FUNCTION_STDIN; /dev/fd/0 shares the /dev/stdin matches arm).
…6-10-26) Tests-only incorporation per the fd-source dual-route ruling (~/workspace/collab-pr-review/REPORT.md §3.2): the slice takes the route, and the two test shapes only the single-issue PR #1685 carried are pinned in the slice's regression file before #1685 is closed as incorporated: - explicit fd-0 redirection wins over piped process stdin (GNU: redir.c binds fd 0 before the builtin runs) - /dev/fd/0 alias spelling of the same binding No production code change; the slice's read-only stdin ladder already resolves both shapes (redirect_cmd before FUNCTION_STDIN; /dev/fd/0 shares the /dev/stdin matches arm).
|
Closing as incorporated per the 2026-10-26 fd-source dual-route ruling (recorded in DECISIONS.md; full comparison in the collab PR review report §3.2/§4.3). The slice PR #1689 was chosen as the single landing route for #1642 and has merged (merge commit As the ruling prescribed, this PR's two unique test shapes were incorporated into the slice tests-only before the merge (commit
Both ran green on the landed tree as part of that file's 13/13 (full slice gates: targeted 30/0/2, lib failure set unchanged {ownership}, differential 305/306 with failure set {ms10}). The rest of this PR's test shapes duplicate the slice's, and its production route is superseded — nothing unique is lost by closing it unmerged. The two routes conflict on the same Thanks for the contribution — including the two test shapes above, which the slice genuinely lacked. |
Integrate PR #1783 onto current master for re-gating on the merged tree. The three precondition commits (aa097de #1626, e6769a7 #1642, 5418fb8 #1643) are patch-equivalent to master (git cherry '-') and drop out of the net diff; the delivery is the three per-issue commits (755d151 #1687, 818da34 #1688, 9f0f347 #1686), unmodified. Conflicts and resolutions (bilateral preservation throughout): - src/executor/external_inner.rs (2 hunks): 1. fd_is_anonymous_pipe: took master's u32-widened S_IFMT comparison (bionic compile fix) — same semantics, supersedes the branch's raw comparison from the #1626 commit. 2. spawn_external_process pin computation: took the branch side — the table is computed by the extracted ambient_fd_pins_for helper (verbatim extraction of the loop master carries inline, plus the injected-group fall-through) and the #1686 command_fd_pins are appended after the ambient pins so a command binding wins a contested slot. The helper also serves the pipeline attach points, so spawn and pipeline paths share one computation; the command-redirect skip ruling is preserved inside the helper, and the #1686 collision ruling (re-open skipped only for injected group redirects) survived in the auto-merged region above. - src/executor/pipeline_exec.rs (4 hunks): union at all four spawn sites — the branch's #1688 attach_ambient_fd_pins call AND master's ms-stopbleed G-02 process.current_dir(&self.shell_state.cwd) stamp both kept at every site (shell-writer consumer loop, spawn_wait_concurrent_external_stages, execute_external_prefix_streaming_tail, execute_external_pipeline_concurrently). - tests (add/add, resolved to the superset side each): issue1626: branch side — #1688 de-ignored the pipeline known-gap pin and added two tests; the only master-only line was the removed #[ignore] itself. issue1642: master side — master carries two extra tests incorporated from PR #1685 under the 2026-10-26 fd-source ruling; the branch side had nothing master lacks. issue1643: branch side — identical to master except the #1687 commit's de-ignore of the numbered-fd known-gap pin. Auto-merged overlap verified: pipeline_stages.rs carries the #1688 attach beside the #438 attach; builtin_redirects.rs carries the #1687 numbered-fd loop; merged-tree diff vs master is exactly the 8 delivery files. src/lexer/continuation.rs untouched.
Fixes #1642.
GNU redir.c do_redirections binds fd 0 before the builtin runs, so opening /dev/stdin reads the redirect. Rubash's /dev/stdin arm fell through to the pipeline buffer or the process stdin instead: with a here-string, heredoc, or
< fileredirect it blocked on a live stdin, or silently read EOF when stdin was redirected (the piped form worked only because the pipe IS the process stdin).The arm now checks first whether the source command carries its own fd-0 stdin redirect, and if so sources the redirect's text via stdin_string_for_command_mut (the same effective-stdin path other builtins use). Bare commands in pipelines keep the existing FUNCTION_STDIN / process-stdin path untouched, and an explicit redirect still wins over a pipe. A failed redirect never reaches here: the simple-command dispatch reports it first (rc 1, source never runs).
Verification (local, master 499a5e2 + this fix, vs GNU):
source /dev/stdin <<< 'echo SRCHS'-> SRCHS, rc 0;< file-> FROMFILE2, rc 0; heredoc -> FROMHEREDOC, rc 0; pipe -> SRCSTDIN, rc 0;/dev/fd/0and/proc/self/fd/0aliases work; pipe + explicit redirect -> redirect wins; missing redirect -> diagnostic, rc 1.readinside the sourced script sees EOF, matching GNU (the redirect text was consumed as the script).