Skip to content

WIP: executor: deliver numbered stdio dups on the simple-command spawn face - #2290

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2278-numbered-stdio-dup
Oct 30, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2278-numbered-stdio-dup

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2278

Problem

On the simple-command spawn face, numbered stdio dups were never
delivered: the numbered redirect walk in
apply_external_fd_delivery skipped dup spellings outright, so
cmd 3<&0 <seed and cmd <seed 3<&0 both left the external
child's fd 3 unbound (EBADF). GNU bash 5.3.20 delivers both
orders — the dup copies the source as bound at its position in
the one ordered redirect walk
(redir.c:237 do_redirections;
redir.c:1138 do_redirection_internal, the dup2 at :1193).

Fix

One mechanism, mirroring the ladder PR #2277 landed for the
{var} channel (deliver_fd_var_dup), adapted to the numbered
walk which has no dynamic-fd applier — new
deliver_numbered_dup in src/executor/external_inner.rs:

  1. A binding this walk already delivered for the source slot
    (walk_opened) stamps/pins at the target — covers
    3<seed 4<&3 chains.
  2. fd-0 sources resolve the command's own stdin binding through
    the 列表级输入 procsub 3< <(...) 未物化(#2196 输入侧兄弟面) #2235 replay (own_input_binding_before) — covers
    <seed 3<&0.
  3. The ambient fd table's endpoint at the source: a File
    endpoint stamps/pins directly (covers exec 3<seed +
    cmd 4<&3); a text snapshot rides a carrier through
    deliver_fd_var_text_binding, generalized to take separate
    snapshot/deliver slots (its three {var} call sites pass the
    same slot twice, unchanged behavior).
  4. A stdio source (≤ 2): if no later entry rebinds the source
    slot, the child's wired slot IS the at-position binding, so a
    child-local pin (the WIP: {fd} variable-form redirects — spawn delivery for all kinds #2277 step-5 shape) is exact. If a later
    entry DOES rebind it (3<&0 <seed, 3>&1 >sink), the
    at-position binding is the ambient one, so the shell's
    ambient stdio descriptor is captured parent-side
    (inheritable dup) and pinned instead — the wired slot will
    hold the later binding and must not be read.

Bindings that are not FileFds are recorded per slot
(NumberedDupBinding) so a later dup in the same list chains
onto the same binding (3<&0 4<&3 <seed delivers the ambient
stream at fd 4). Move spellings (4<&3-) are not intercepted —
they keep their existing fall-through. An unresolvable source
delivers nothing; closed sources are diagnosed on the redirect
preflight face, as in the {var} ladder.

Tests

New target tests/issue2278_numbered_stdio_dup_regressions.rs
(13 pins): both dup orders with a foreign dd observer reading
/dev/fd/3, the issue's nested-rubash seed shapes in both
orders, plain stdio dup, numbered chain, ambient numbered
source, chain through a stdio dup, the output order pair
(3>&1 >sink → ambient stdout; >sink 3>&1 → the file), plus
two controls (numbered file binding; the #2277 {var} stdio
dup through the shared walk). Expectations were byte-verified
against the GNU bash 5.3.20 oracle with the probe cells kept in
the cluster workdir (probes/cells, oracle table in
probes/README.md).

Per the compile-rationing regime the pins were not run
locally
(only cargo check + cargo check --test issue2278_numbered_stdio_dup_regressions, both clean); the
collector batch-verifies them under a scrubbed fd environment,
together with the control targets issue2272 (24 pins),
issue2235, issue2255, issue2256, and issue2270.

caomengxuan666 and others added 2 commits October 30, 2026 23:12
Refs #2278

The numbered redirect walk in apply_external_fd_delivery skipped
dup spellings outright, so `cmd 3<&0 <seed` and `cmd <seed 3<&0`
both left the child's fd 3 unbound (EBADF). GNU services every
dup in its single ordered walk with a dup2 of the source as bound
at that walk position (redir.c:237 do_redirections; redir.c:1138
do_redirection_internal, dup2 at :1193).

Add deliver_numbered_dup, mirroring the #2277 {var} ladder by
mechanism: (1) a binding this walk already delivered for the
source, (2) the #2235 fd-0 replay for the command's own stdin
binding, (3) the ambient fd table's endpoint at the source
(a File endpoint stamps/pins; a text snapshot rides a carrier
through the generalized deliver_fd_var_text_binding), (4) a
stdio source — a child-local pin when no later entry rebinds the
source slot, or a parent-side capture of the ambient stdio
descriptor when one does (`3<&0 <seed` delivers the ambient
stdin, not the seed the later entry wires into the child's
fd 0). Bindings that are not FileFds are recorded per slot so a
later dup in the same list chains onto the same binding. Move
spellings (`4<&3-`) keep their existing fall-through.

Regression pins in tests/issue2278_numbered_stdio_dup_regressions.rs
(both dup orders, the output order pair, chains, controls),
expectations byte-verified against GNU bash 5.3.20 probe cells.
Pins are not run locally under the compile-rationing regime; the
collector batch-verifies them under a scrubbed fd environment.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 23:24
@caomengxuan666
caomengxuan666 merged commit f2cc4c6 into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2278-numbered-stdio-dup branch November 2, 2026 01:09
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