Repository navigation
WIP: fix pending {fd} close list position on in-process and script faces (#2322) - #2367
Merged
Merged
Conversation
…script faces
GNU applies a command's redirect list as one ordered walk over the
live descriptor table (redir.c:246 do_redirections): a {var}<&-
close removes its descriptor at its position (redir.c:1219-1248),
so a dup positioned after a same-list close of its source fails,
and a {var} dup assigns its variable only after the dup succeeds
(redir.c:1010/1113 redir_varassign) — a rejected command leaves
the failing entry's variable unset while earlier binds persist.
In-process faces (builtin/function): the {var} applier serviced a
doomed dup against the raw fd table — pending closes were only
recorded for the gate — and bound the variable before the gate
rejected the command (GNU: unset). The dup arms now consult a
list_closed overlay of descriptors closed by earlier entries of
the same list, maintained by apply_dynamic_fd_var_redirects as it
walks (recorded pending closes and fixed closes poison, binds
revive); call sites whose closes are performed immediately pass
an empty set.
Same-exe script face: numbered outputs bound in a separate later
pass, after the #2310 segmented {var} walk, so a {v}>&- close of
a list-bound output never reached the child. Outputs now bind per
segment beside the inputs (open_compound_output_redirects_in in
command_input_scope.rs; execute_direct_shell_script consumes the
segment saves), perform_script_fd_var_close consults the output
saves, and the own-binding predicate is direction-agnostic — one
table entry per descriptor, so an input bind governs a later
output-spelled dup and vice versa (restores
issue2310_output_dup_resolves_own_bind).
Pins: tests/issue2322_close_position_regressions.rs, 13 tests,
expectations byte-verified against GNU bash 5.3.20 script-file
probes under a scrubbed fd layout (only 0/1/2 open at launch).
Refs #2322
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.
Refs #2322 — do not merge/close from this PR; the parent session adjudicates.
GNU contract
One ordered walk over the live descriptor table (redir.c:246
do_redirections). A{var}<&-close removes its descriptor at its position (redir.c:1219-1248), so a dup after a same-list close of its source fails withredirection error: cannot duplicate fd; a{var}dup assigns its variable only after the dup succeeds (redir.c:1010/1113), so a rejected command leaves the failing variable unset while earlier binds persist. Verified against the GNU bash 5.3.20 oracle binary with script-file probes.Divergences fixed
{var}applier serviced a doomed dup against the raw fd table (pending closes were only recorded for the gate) and bound the variable before the gate rejected the command —w=[10]where GNU leaves it unset. Dup arms now consult alist_closedoverlay maintained byapply_dynamic_fd_var_redirectsas it walks (pending + fixed closes poison, binds revive); immediate-close call sites pass an empty set.{var}walk, so a{v}>&-close of a list-bound output never reached the child (child saw the ambient descriptor on the dup and the "closed" output still open). Outputs now bind per segment beside the inputs (open_compound_output_redirects_in);perform_script_fd_var_closeconsults the output saves; the own-binding predicate is direction-agnostic (one table entry per descriptor — an input bind governs a later output-spelled dup and vice versa, restoringissue2310_output_dup_resolves_own_bind).Verification (local, fd-scrubbed runner; binary artifact timestamp-verified in-view)
tests/issue2322_close_position_regressions.rs: 13/13 pass.Known residual (NOT fixed here, characterized in the cluster REPORT.md)
Foreign-spawn face only: with a
{var}dup AND a pending close of its source in the same list, the stage spawner re-opens the dup's target fileO_TRUNCimmediately afterwait4, destroying bytes the foreign child wrote through the dup fd (strace-verified; call goes throughstd::fs::OpenOptions::openin the spawner post-wait finish path; exact call site not isolated — no gdb/lldb on the VM). Shell children are unaffected. Recommended as its own follow-up issue/cluster rather than a tail-end patch to the shared spawner finish path.