Skip to content

WIP: pipeline stages apply their own redirects via the shared external path (rubash#2255) - #2262

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2255-stage-redir
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2255-stage-redir

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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 -c printed 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)

  1. apply_external_fd_delivery (external_inner.rs): the fd-delivery segment of spawn_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_process calls 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).
  2. Sequential stage spawner (pipeline_stages.rs): execute_external_pipeline_stage_inner now calls that helper (replacing its ambient-only attach_ambient_fd_pins) and closes the parent-side duplicates once its spawn resolves; and its fd-0 adjudication now routes the dup/close winners through apply_external_stdin_redirect too, not just the file winners.
  3. Inline-arm decline gate (pipeline_exec.rs): a non-builtin stage whose own list binds a numbered input fd declines to the external stage spawner — the inline text arms hold no per-element fd table, so the binding (and any <&N dup or /dev/fd/N operand 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 with redirect_in set or a list-only (fd > 2) redirect, so every numbered-redirect stage lands on the sequential path above.

Integration note vs PR #2253 (#2235)

Verification

Per the compile-rationing order (2026-10-31): local work was code + pins only — cargo check at most, no test runs, no build-slot use. Probe battery probes/p2255.sh (workdir) and the pins in tests/issue2255_pipeline_stage_redirects.rs are for the integration-side batch run; expected GNU transcripts for e8/f6a/f6b are the #2235 battery's recorded GNU outputs (all 10).

…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
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 18:22
@caomengxuan666
caomengxuan666 merged commit 69ebca1 into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2255-stage-redir branch November 2, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant