Repository navigation
WIP: {fd} variable-form redirects — spawn delivery for all kinds - #2277
Merged
Merged
Conversation
…g in the parent table (Refs #2272) Close-form targets ({var}<&- / {var}>&-) and move-form dup sources were closed in the shell's own fd table by execute_dynamic_fd_var_redirect. GNU scopes a command's closes to the command (in the fork for external commands): an exec-bound descriptor survives a command that closes it through a {var} entry. Closing in the parent table destroyed the binding for good, and the ordered redirect preflight — replaying the list against the table — then rejected the very dup the applier had just serviced ({v}<&3- failed "cannot duplicate fd"). On the simple-command funnel path (new defer_closes parameter; the exec face and the compound scope path keep their persistent closes) the applier now only records the descriptors in fd_var_pending_closes. undo_child_fd_var_redirects restores the snapshots apply_external_fd_delivery took when it performed the closes for a spawn, and drops records no delivery consumed.
…2272) The shared spawn delivery helper skipped every fd_var entry, so the bindings the dynamic-fd applier installed in the fd table reached external children only when they happened to be plain File endpoints under the ambient stamp. Add the fd_var channel inside the helper, reusing the existing env + pre_exec pin machinery (no new protocol shapes): - deferred {var} closes recorded by the applier are performed in the table (snapshotted for the undo) before the inheritance stamp, so the child does not inherit those slots; - heredoc / here-string bodies (Text endpoints) are materialized into carrier files and stamped/pinned at the var's number, including the heredoc_redirects entries; - dup forms resolve the source in GNU's walk order (redir.c:237): a binding this walk already delivered for the source, the #2235 fd-0 replay for the command's own stdin binding, the applier's ambient copy (File rides the ambient stamp; a text snapshot rides a carrier), and finally a stdio source pinned child-locally at the var's number. When the applier could not bind (an own-list source), the delivery number is allocated with the applier's own lowest-free rule. own_input_binding_before and dynamic_fd_variable_value widen to pub(in crate::executor) for the replay/lookup.
) GNU applies every pipeline element's redirections in the element's fork (execute_cmd.c:2620 -> redir.c:237), {var} entries included, but the sequential stage spawner bypasses the simple-command funnel whose applier binds {var} entries into the fd table — so a stage's {var} bindings never existed and the shared delivery helper had nothing to deliver (every kind failed EBADF in the stage's child). Run the applier in execute_external_pipeline_stage, scoped by the same undo the external face uses; a failed {var} redirect fails the element with status 1 while the pipeline continues, like a numbered redirect failure. Elements carrying fd_var redirects already decline the concurrent stage path (is_list_only_redirect), so the sequential spawner is the only stage face to serve.
24 pins covering every GNU-supported kind for external commands: file in/out/append/read-write, heredoc, here-string, two-var list-order allocation, ambient-slot collision, dup of an ambient file fd / an ambient heredoc / the command's own list bindings (input and output) / its own stdin redirect / ambient stdin / stdout / stderr, close form (child closed, parent binding and variable survive), unset-var close (ambiguous redirect), move form (child copy + source closed + parent keeps the source), missing-file abort, three pipeline-stage cells, a numbered-fd control, and the in-process persistence guard. Observers are real spawns only (a nested rubash binary, or dd for the stdio faces) — never ./reader.sh scripts, which rubash runs in-process and would pass vacuously. Expectations byte-verified against GNU bash 5.3.20 oracle probes.
This was referenced Oct 30, 2026
…emantics Refs #2272 The pin expected the parent's post-command read of ambient fd 10 to replay amb-line-1 after the child had already read that same inherited descriptor to EOF. GNU bash 5.3.20 oracle probes (exact shape / child-skips-ambient / plain-fork controls) show the forked child's duplicate descriptor shares the parent's open file description, offset included: the child's cat <&10 advances the shared offset to EOF, so the parent's trailing read prints nothing. The PR tree's output matches GNU byte-for-byte on all three probes; the product behavior was already correct - only the pin's expectation was wrong. The trailing read stays in the pin: it still guards that the parent's fd 10 binding survives (a destroyed binding would fail the redirect and the script's exit code).
caomengxuan666
marked this pull request as ready for review
October 30, 2026 20:47
This was referenced Oct 30, 2026
SpookyWaste
pushed a commit
to SpookyWaste/rubash
that referenced
this pull request
Nov 12, 2026
Refs unixwin#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 unixwin#2277 {var} ladder by mechanism: (1) a binding this walk already delivered for the source, (2) the unixwin#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.
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: {fd} variable-form redirects — spawn delivery for all kinds (Refs #2272)
The dynamic-fd applier bound
{var}descriptors into the shell's fd table, butapply_external_fd_deliveryskipped fd_var entries outright, so external children never received the bindings (or received nothing where GNU delivers at the var's number). This PR adds the fd_var channel inside the shared delivery helper, per kind:<,>,>>,<>) already rode the ambient env+pin stamp once bound — verified against the GNU oracle, no change needed.{var}bindings exist for the shared helper to deliver; a failed{var}redirect fails the element with status 1, like a numbered one.Regression pins:
tests/issue2272_fdvar_spawn_delivery_regressions.rs(24 pins; expectations byte-verified against GNU bash 5.3.20 oracle probes — foreign-observer children only, no in-process script readers).Compile rationing: local verification is
cargo check+cargo check --testsonly; all test execution is pending the collector batch / CI.Refs #2272