Repository navigation
fix(executor): compound scope undo covers {var} closes (#2614) - #2617
Merged
Merged
Conversation
GNU registers every descriptor mutation of a command's redirections
as a reversible undo record (redir.c do_redirections:
add_undo_redirect / add_undo_close_redirect; the dup/move case also
saves the source via add_undo_redirect (redir_fd, r_close_this, -1),
gated on the destination being active) and undo_redirections
replays the whole chain. The compound scope's snapshot/restore sets
only covered what the numbered openers overwrote, so the {var}
pass's immediate closes - a move source ({v}>&9-) or a pure close
({v}>&-) - survived the group and killed the parent's descriptor;
its scope-end cleanup also closed BY VARIABLE NAME, re-closing a
close-form variable's just-restored target. The numbered input
opener never saved a move source at all, and the output opener
saved one unconditionally where GNU's save is activity-gated
(rubash#1235: a move onto a closed target closes the source for
good).
- snapshot every {var} close target before the entry applies and
replay the snapshots on every exit (body end, dup-preflight
abandonment, mid-list apply/open failure)
- close scope-bound descriptors by recorded (variable, fd) pairs,
only while the variable still names the bound descriptor
- gate both numbered openers' move-source snapshots on the
destination being open at the walk position
Pins: issue2614_scope_restore_undo_regressions (UNVERIFIED-BY-CAPTAIN)
caomengxuan666
marked this pull request as ready for review
November 2, 2026 12:35
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 #2614
Code-only cluster delivery (captain verifies/merges centrally). Full write-up: the cluster REPORT (restore-set audit, approach, unrestorable-by-design items).
What
The compound scope in
command_input_scope.rssnapshot/restores per kind, and its restore set omitted the closes its{var}pass performs immediately: a move-form{v}>&9-(or pure{v}>&-) inside{ ...; }closed the parent's descriptor for good (D1: POST dies9: Bad file descriptor). GNU registers every descriptor mutation in the command's undo chain (redir.cdo_redirections/undo_redirections; the dup/move case saves the source viaadd_undo_redirect (redir_fd, r_close_this, -1)).SavedDynamicClose: every{var}entry's close targets are snapshotted before the entry applies and replayed on EVERY exit (body end, dup-preflight abandonment, mid-list apply/open failure — those exits previously unwound nothing).One file changed:
src/executor/command_input_scope.rs. No trap_exec.rs / pipeline / lexer changes.Pins
tests/issue2614_scope_restore_undo_regressions.rs— stemissue2614_scope_restore_undo_regressions, 12 tests, expectations byte-verified against GNU bash 5.3.20 script-file probes. UNVERIFIED-BY-CAPTAIN (localcargo check --testsclean only).Guards: issue2322_close_position_regressions, issue2281_pending_close_positions, issue2562_numbered_dup_same_list, issue2503_born_closed_stdin_regressions.