Repository navigation
fix(fd): duplicate symbolic stdio endpoints in exec-walk undo saves (Fixes #4024) - #4032
Merged
Merged
Conversation
Two captain-graft changes on top of the PR's fix for #4024: - fd_table.rs: inside FdTable::exec_walk_saved_entry only, the stdio_dup closure now returns io::Result and the three silent .or_else fallbacks to the symbolic clone are deleted in favor of ? propagation (method signature and the trap_exec.rs call site unchanged; doc comment corrected). GNU's undo save is the same fcntl and its failure fails the redirection; the silent fallback parked exactly the dead alias #4024 is about. - tests/issue4024_exec_walk_save_stdio_graft.rs: 8 pins ported from the captain lane's probe set (p02/p03/p04/p08-file/p06/p11 plus p05/p07 guards), covering the faces the PR's own pin file did not. Verified on the captain's cloud oracle (GNU bash 5.3.20): probe matrix p01-p11 + p13 byte-identical to GNU; graft pins 8/8 on this tree, 6 red / 2 guard-green on pristine (fail-first); own pins 7/7; issue3991 15/15, 2613 9/9, 2615 13/13, 3806 4/4, 3731 11/11, 3633 coproc_child green (dead_coproc red is baseline-identical). Full account in the PR body's Captain graft + verification section.
This was referenced Nov 21, 2026
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.
Root cause
GNU's undo save is a real descriptor (
redir.c:1296 add_undo_redirect()runsfcntl(fd, F_DUPFD, SHELL_FD_BASE)before the redirect mutates the source), so the save survives the redirector's own close. Rubash's exec walk cloned the symbolicStdout/Stderr/InheritedProcessStdinendpoint for the save; when>&-retired the real descriptor (kernel_close_persistent), a later1>&10in the same list bound a dead endpoint and subsequent output silently vanished.GNU C citations (
third_party/bash/redir.c,execute_cmd.c):redir.c:1296(add_undo_redirect),redir.c:86(SHELL_FD_BASE = 10)redir.c:790,1138-1271(do_redirection_internal),redir.c:230-267(do_redirections)execute_cmd.c:5606-5634(RX_UNDOABLE/ exec undo-list disposal)Fix
src/executor/fd_table.rs: addFdTable::exec_walk_saved_entryto upgrade symbolic stdio endpoints (Stdout,Stderr,InheritedProcessStdin) to private descriptor duplicates (dup_adopted_fdon Unix /duplicate_handleon Windows) when they name the real process descriptor.src/executor/trap_exec.rs: useexec_walk_saved_entryat the exec-walk save site and addstdout_marker_names_processso active capture routing is preserved.tests/issue4024_exec_walk_save_stdio_source.rs(7 tests).Verification
/usr/local/bin/bash5.3.20.rustfmt --edition 2021 --checkclean on all 3 files.cargo test --test issue4024_exec_walk_save_stdio_source: 7/7 pass on Windows and Linux.Captain graft + verification
This PR was adopted as the merge vehicle for #4024 after captain review
found its mechanism sound and its capture routing more careful than the
captain lane's own (retired) reconstruction. The graft commit on top
(
59b4f358) adds verification, the missing pin coverage, and onedup-failure handling fix (§3). The PR's own product change is otherwise
unchanged.
1. Oracle matrix (captain's cloud GNU bash 5.3.20)
The captain lane's probe set for #4024 (script files; stdout + stderr +
rc byte-compared) run against this PR's tree, pristine
c885c5a5, andGNU bash 5.3.20:
11; pristine diverges on exactly the 9 known silent-loss shapes,
and the p05/p07 guards agree on all three columns.
payload delivered to the script's stderr).
residual A. This tree is byte-identical to pristine there; the PR
neither fixes nor regresses that shape.
2. Grafted pins
tests/issue4024_exec_walk_save_stdio_graft.rs(8 pins) ports thecaptain lane's probe shapes the PR's own pin file did not cover: p02
(two saves claiming slots in order), p03 (dup to a numbered fd), p04
(multi-line service), p08 file-form stdin continuation reads, p06
(save-slot disposal with diagnostic text), p11 (two-stdio full
diagnostic text), and the p05/p07 guards.
(including p02), both guards pass: fail-first verified.
3. Dup-failure handling (the graft's one product change)
GNU errors when the undo save's F_DUPFD fails (oracle pfail:
redirection error: cannot duplicate fd: Too many open files). Thereview flagged this PR's silent fallback to the symbolic clone as its
one design flaw. The graft removes it, strictly inside
FdTable::exec_walk_saved_entry: thestdio_dupclosure now returnsio::Result, all three.or_elsesilent fallbacks are deleted infavor of
?propagation, and the doc comment is corrected. Methodsignature and the trap_exec.rs call site are unchanged.
Verified non-regressing: after the change the full matrix above is
unchanged (p01–p11 and p13 still byte-match GNU; own pins 7/7; graft
pins 8/8).
One honest limit: the pfail shape itself still does not emit GNU's
cannot duplicate fddiagnostic in rubash. strace shows that when thefd table is saturated, rubash's save is never materialized through a
kernel dup at all (no F_DUPFD is attempted for that walk), so there is
no failure at this site to propagate; the shape still fails loudly
(rc=1,
echo: write error: Bad file descriptor). Reproducing theEMFILE diagnostic belongs to the save-slot allocation layer, not to
this PR — recorded for the captain as residual B.
4. Residual A: nested exec walks leave the parent's fd 1 dead
The p12 difference and the pfail shapes' missing final line share one
root, proven pre-existing (pristine byte-identical) and independent of
this PR's mechanism — no dup-back and no save content are involved:
( exec >&- 1>&10 ); echo after— GNU printsafter; rubashprints nothing.
x=$(exec >&-; echo hi); echo "cap=[$x]"— GNU printscap=[](with the write-error diagnostic on stderr, which rubash matches);
rubash loses the outer echo as well.
An
execredirect walk that closes fd 1 inside a subshell or commandsubstitution leaves the parent shell's fd 1 dead in rubash. That is
a cross-context walk-disposal defect adjacent to — but distinct from —
#4024's save-endpoint form; it is recorded for the captain as a
separate residual and is not fixed here.
5. Adjacency (this tree, cloud)
issue3991 pins 15/15; issue2613 9/9; issue2615 13/13; issue3806
4/4; issue3731 11/11; issue3633 coproc_child green (
dead_coprocred, byte-identical result on pristine — baseline environmental);
lib
fd_tablestem 8/8.What this PR deletes
The PR itself deletes nothing beyond the single replaced call line at
the exec-walk save site (
saved_entry→exec_walk_saved_entry);saved_entryitself and its other call sites (procsub snapshot, fd0snapshot) are untouched. The captain graft additionally deletes the
three silent
.or_elsefallback arms insideexec_walk_saved_entry(§3) and adds one pin file.