Repository navigation
WIP: fix(fd): script face re-resolves fd_var dups against the command's own binds (#2310) - #2321
Merged
Merged
Conversation
…n binds Refs #2310 GNU applies a command's redirect list as ONE ordered walk over the live descriptor table: do_redirections (redir.c:237) services each element in order, a REDIR_VARASSIGN dup allocates with fcntl(F_DUPFD) against the table as bound so far (redir.c:1144-1150) and copies the descriptor as bound at that walk position (redir.c:1193, dup2), a varassign failure closes the just-duplicated descriptor (redir.c:1161-1166), and a {var}<&- close closes the descriptor the variable holds at its position (redir.c:1239-1248). The same-exe script face (execute_direct_shell_script) never revisited the funnel's pre-dispatch fd_var service: dups were copied from the AMBIENT table before the command's own binds existed, and closes were only recorded, never performed for the child. `rubash obs.sh {v}<&- 9<f9 {w}<&9` therefore delivered the parent's ambient seed at fd 10 where GNU delivers the f9 content, and `{v}<&-` left the child reading the parent's fd 9. Fix by mechanism, mirroring the walk: the face now binds its numbered inputs in segments split at the command's {var} entries (open_compound_numbered_input_redirects_in carries the segment range; the whole-list wrapper is unchanged for other callers) and applies each entry's effect at its segment point, when the table holds exactly the binds GNU's walk would have produced by then. A dup whose source an earlier own-list entry binds is re-copied from the at-position table (or bound outright when the ambient-only applier bound nothing, the allocator then seeing the command's own binds like F_DUPFD does); a close is performed in the table with a pre-command snapshot — taken from the numbered accumulator or the heredoc saves when an earlier own-list bind already snapshotted the slot — pushed to fd_var_close_restore, so the paired undo restores the parent (the spawn delivery prologue's bookkeeping). This also repairs the parent losing its own fd 9 to the undo on this face, which reproduced on master for every {v}<&- shape. Verification (oracle: GNU bash 5.3.20 binary, script-file probes): 13 shapes byte-equal with GNU, including the headline, the shared-offset dup, dup-before-bind, the output spelling, a numbered-dup chain, close delivery, and parent restoration after close and bind-then-close commands. Pins: tests/issue2310_scriptface_fdvar_regressions.rs 8/8 under a scrubbed fd environment; controls issue2272 24/24 and issue2279 13/13 stay green (no issue2281 test target exists at this base). Full regression + lib batches are the collector's.
… field (Refs #2310) Master's #2281 made fd_var_pending_closes carry (position, fd) pairs; this branch's apply_script_fd_var_entry still took &mut Vec<u32>, which failed compilation on the composed tree (CI E0308). The callee now takes &mut Vec<(usize, u32)> and matches records on the fd component at its two consumption sites — the branch's own semantics (consume-by-fd) unchanged.
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 #2310 (1.5.0 milestone blocker). Draft for the collector's batch + composition.
Defect
The same-exe script face (
execute_direct_shell_script) serviced a command's{var}redirects from the funnel's pre-dispatch pass only: dups were copied from the ambient fd table before the command's own binds existed, and{var}closes were only recorded, never performed for the child. Headline:rubash obs.sh {v}<&- 9<f9 {w}<&9delivered the parent's ambient SEED at fd 10; GNU delivers the f9 content. The spawn faces already resolve at position (#2272/#2279); this face did not.GNU ground (clean-room: behavior facts)
redir.c:237do_redirections— one ordered walk over the list, each element applied to the live table in order.redir.c:1144-1150— REDIR_VARASSIGN dup allocatesfcntl(redir_fd, F_DUPFD, SHELL_FD_BASE)against the table as bound so far.redir.c:1193— the dup copies the descriptor as bound at that walk position (dup2).redir.c:1161-1166— a varassign failure closes the just-duplicated fd.redir.c:1239-1248—r_close_this+ REDIR_VARASSIGN closes the fd the variable holds at that position.Fix (by mechanism, no per-shape guards)
execute_direct_shell_scriptnow binds numbered inputs in segments split at the{var}entries and applies each entry's dup/close effect at its segment point, when the table holds exactly the binds GNU's walk would have produced by then.open_compound_numbered_input_redirectsis split into a whole-list wrapper +open_compound_numbered_input_redirects_in(range, &mut saved); the accumulator's first-snapshot-wins dedup makes segmented binding restore-identical for all existing callers.9<f9 10<&9 {w}<&10→ fd 11, matching GNU).fd_var_close_restore— the spawn prologue's bookkeeping — so the paired undo restores the parent. Side effect: the parent no longer loses its own fd 9 to the undo on this face (reproduced on master for every{v}<&-shape).Files
src/executor/external_finish.rs— call site swap (bind block only).src/executor/command_input_scope.rs— segmented range variant +SavedNumberedFdaccessors.src/executor/trap_exec.rs— the segmented binder + at-position fd_var applier (one new block, +280 lines).tests/issue2310_scriptface_fdvar_regressions.rs— 8 pins, GNU expectations.No overlap with PR #2300: this change touches neither
src/executor/external_inner.rsnorredirection.rs.Verification (local, scrubbed fd environment)
regression+libbatches deliberately left to the collector.Known adjacent gap (not fixed here, flagged in REPORT.md and the pin file header)
s4:9<f9 {v}<&- {w}<&9(v=9) — GNU rejects the command (the dup's source is closed at its walk position); both rubash faces currently run the child. It is a pending-close-position question in the shared applier records (positions are not recorded), separate from this issue's dup-resolution/close-delivery defects.