Repository navigation
WIP: pipeline stages apply their own redirects via the shared external path (rubash#2255) - #2262
Merged
Merged
Conversation
…l path (rubash#2255) GNU forks every pipeline element and runs ONE ordered do_redirections walk in the child (redir.c:237 do_redirections; each entry's word expanded at its own turn, redirection_expand redir.c:298; execute_cmd.c:2620 execute_pipeline). A stage's own numbered bindings, its fd-0 dup of such a binding, and its numbered outputs therefore take effect for the element exactly as for a simple command. The stage runners never ran that application: a stage's fd 0 was composed from the captured-input channel and its redirect list was dead text, so the #2235 probe battery's pipeline cells e8/f6a/f6b printed 0 where GNU prints the seed's byte count (`cat 3<seed <&3 | wc -c` -> 10). Three parts, no stage-local parallel implementation: - external_inner.rs: extract spawn_external_process's fd delivery segment (ambient fd-table __RUBASH_FD_* stamps, the command's own numbered redirects opened + stamped/pinned, the unix pin registration) verbatim into the shared helper apply_external_fd_delivery. spawn_external_process calls it; its signal-reset pre_exec now registers after the pin closure (independent closures, order inert — documented on the helper). - pipeline_stages.rs: the sequential stage spawner runs that helper (replacing its ambient-only attach_ambient_fd_pins) and closes the parent-side duplicates once its spawn resolves; its fd-0 adjudication now routes the dup/close winners through apply_external_stdin_redirect as well, not only file winners. - pipeline_exec.rs: a non-builtin stage whose own list binds a numbered input fd declines from the inline slot arms (which hold no per-element fd table) to the external stage spawner — the same decline shape as the existing fd-0 file gate. Builtin stages keep the stage-subshell route; {var} entries stay with the dynamic-fd applier. The concurrent pipeline loops need no change: their admission (concurrent_external_stage_spec) already declines any stage with redirect_in set or a list-only (fd > 2) redirect, so every numbered-redirect stage lands on the sequential path above. Pins: tests/issue2255_pipeline_stage_redirects.rs — delivery pins (sh child, rubash child, numbered output) plus the e8/f6b and procsub composition pins, which are green once PR #2253 (#2235's own-list replay inside apply_external_stdin_redirect and its arms inside the extracted delivery loop) is integrated alongside; two controls green on master. Refs #2255 Refs #2235
This was referenced Oct 30, 2026
caomengxuan666
marked this pull request as ready for review
October 30, 2026 18:22
This was referenced Oct 30, 2026
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: pipeline stages apply their own redirects through the shared external path (rubash#2255)
Refs #2255. Refs #2235 (composition — see the integration note).
Problem
A pipeline stage's own redirects were never applied:
cat 3<seed <&3 | wc -cprinted 0 (GNU: 10 — #2235 probe battery cells e8/f6a/f6b). The stage runners composed fd 0 from the captured-input channel and never ran the ordered redirect application a simple external command runs. GNU forks every element and runs ONE ordered do_redirections walk in the child (redir.c:237; execute_cmd.c:2620 execute_pipeline).Change (three parts, no stage-local parallel implementation)
apply_external_fd_delivery(external_inner.rs): the fd-delivery segment ofspawn_external_process— ambient fd-table__RUBASH_FD_*stamps, opening the command's OWN numbered (fd ≥ 3) redirects with env stamps + unix pins, and the pin registration — extracted verbatim into a shared helper.spawn_external_processcalls it; behavior there is unchanged except its signal-reset pre_exec now registers after the pin closure (independent closures; order inert, documented in the helper).execute_external_pipeline_stage_innernow calls that helper (replacing its ambient-onlyattach_ambient_fd_pins) and closes the parent-side duplicates once its spawn resolves; and its fd-0 adjudication now routes the dup/close winners throughapply_external_stdin_redirecttoo, not just the file winners.<&Ndup or/dev/fd/Noperand reading it) was silently dropped. Builtin stages keep the stage-subshell route; {var} entries stay with the dynamic-fd applier. Same decline shape as the existing fd-0 file gate.The concurrent pipeline loops need no change: their admission (
concurrent_external_stage_spec) already declines any stage withredirect_inset or a list-only (fd > 2) redirect, so every numbered-redirect stage lands on the sequential path above.Integration note vs PR #2253 (#2235)
apply_external_stdin_redirect(called here for stage fd 0) and its stash/alias arms live inside the delivery loop this PR extracts intoapply_external_fd_delivery. If WIP: list-level input procsub materialization (rubash#2235) #2253 lands first, its two loop hunks re-apply inside the helper body; if this lands first, WIP: list-level input procsub materialization (rubash#2235) #2253's external_inner.rs hunks move into the helper. Either order is mechanical; the helper's body is master's loop verbatim.Verification
Per the compile-rationing order (2026-10-31): local work was code + pins only —
cargo checkat most, no test runs, no build-slot use. Probe batteryprobes/p2255.sh(workdir) and the pins intests/issue2255_pipeline_stage_redirects.rsare for the integration-side batch run; expected GNU transcripts for e8/f6a/f6b are the #2235 battery's recorded GNU outputs (all10).