Repository navigation
fix(executor): retire the opposite fd arm on each redirect bind (Fixes #3655) - #3768
Conversation
…3655) GNU redir.c do_redirection_internal applies each redirect with dup2 onto its redirector (the r_reading_until case calls here_document_to_fd at redir.c:1065-1072), so a later entry on the same fd replaces the descriptor wholesale -- last-wins. Rubash's fd table kept input/output arms independent: `open_input` replaced only the read arm and `open_output` only the write arm, so after `exec 14<<A 14>file` fd 14 still carried the heredoc's read arm and `read -u 14` saw `first` on a descriptor GNU leaves write-only. Make both primitives retire the opposite arm (dup2 wholesale, with the rubash#3213 retire-before-materialize ordering) and route every legitimate dual-arm `<>` install through a single FdTable::open_readwrite -- one O_RDWR description, installed once (set_fd_readwrite_file, function-call stdin, external finish/setup, builtin net binds, dynamic {var} binds, respawn restore, inherited fds, and the pipe-complementary write arms). Pin: tests/issue3655_heredoc_vs_file_redirect.rs -- 10 cells, every expectation byte-verified against GNU bash 5.3.20.
…(Refs #3655) CI run 43824819839: E0308 at external_setup.rs:2713 — the enclosing match binds ProcsubSpawnFd::File arms by reference (match ergonomics), so `read` is `&Rc<FileFd>` where `FdReadEndpoint::File` expects `Rc<FileFd>`; the write side already had `.clone()`, the read side did not. Single error in the crate; fd_table.rs:264 is only the variant-definition note, not a second error.
…ash#3770 (Refs #3655) Leg 2 on X299 (head 6e9e6f2): 9/10 green; only issue_fd0_heredoc_then_truncate_file_wins red — stdout was the expected `rc=1 x=` (the heredoc read arm IS retired) but stderr was empty where GNU prints `read: 0: read error: Bad file descriptor`. That missing diagnostic is a read-builtin face, not the redirect ordering this PR fixes: filed as rubash#3770 (no existing issue on the face; `read_fd_is_available` fd-0 arm checks only `is_closed(0)`). The cell now pins the ordering face only (rc + empty x + empty out.txt) and cites #3770 for the diagnostic.
Captain review — PASSHead Mechanism — GNU anchors checked against source: Legs (X299, logs fetched to the lane workdir CI (final head, run 43830136536) — three red legs (Rust tests / goldens+canaries / macOS), each failing on the single known baseline cell Guard / sequencing — full open-PR scan over the 7 touched files: same-file open PRs (#3738/#3740 ordered pair, #3723 family, #3688, #3746, #3652, #3377, #3140, #3363, …) are all in Wave 2 / held / merge-owed states; none is merged, so this PR merges first and the rest rebase onto it. Residual — the full-tree |
…ly (Refs #3770) GNU builtins/read.def:911 — a hard read(2) failure is reported as `read: <fd>: read error: <strerror>` and the builtin fails; it is not plain EOF. After `exec 0<<A 0>out.txt` fd 0 is open but write-only (#3655 retires the heredoc read arm), and the plain-`read` path reached the transports with no availability gate (the -u arm diagnoses before the transports; plain read never calls read_fd_is_available), so every transport returned None and the builtin fell through to the silent-EOF arm. Fix (mechanism): read_virtual_fd_stdin records a hard read error when the table owns an open descriptor with no read arm — the same read_error channel the EISDIR endpoint (#1495) and hard read failures in read_file_bytes use, rendered by the read builtin's existing error arm. `is_open` without `is_open_for_read` is exactly open-but-not-readable: an entry with no read arm at all (a pipeline stage's fd 0) has is_open false, so its transports still own it, and a present-but- exhausted read arm stays a real silent EOF. Pin: tests/issue3770_read_writeonly_fd0.rs (8 cells; fd-0 cell is the full expectation of #3768's relaxed J cell). UNVERIFIED-BY-CAPTAIN
Fixes #3655
GNU applies redirects left-to-right, last-wins: redir.c do_redirection_internal walks the list in order and each entry dup2's onto its redirector (the r_reading_until case calls here_document_to_fd at redir.c:1065-1072). After
exec 14<<A 14>fileGNU leaves fd 14 write-only, soread -u 14fails EBADF. Rubash's fd table kept input/output arms independent (open_inputreplaced only the read arm,open_outputonly the write arm), so fd 14 still carried the heredoc's read arm andread -u 14sawfirst.Fix (mechanism, not a case guard):
FdTable::open_input/open_outputnow retire the opposite arm (dup2 wholesale, keeping the rubash#3213 retire-before-materialize ordering), and every legitimate dual-arm<>install goes through a singleFdTable::open_readwrite— one O_RDWR description, installed once. Converted sites:set_fd_readwrite_file(all arms), function-call stdin (3), external finish/setup, builtin net binds, dynamic{var}binds (file + procsub arms), respawn restore, inherited fds, and the pipe-complementary write arms (walk +set_fd_readwrite_filedup arm). Input/output setters clear the opposite arm's env ledger with the bind.Pin:
tests/issue3655_heredoc_vs_file_redirect.rs— 10 cells (heredoc-then-truncate/append, both reverse controls, heredoc-vs-input-file both orders,<>pair shared-offset guard, here-string both orders, fd-0 face). Every expectation byte-verified against GNU bash 5.3.20 (oracle probe in the lane workdir). Fail-first + X299 legs: see REPORT.md in the lane workdir (to be attached at review).本 PR 删除了什么
fd 表双臂独立共存的不变量:同 fd 上的输入/输出绑定不再各自保留对方臂;除
<>单次安装外,双臂共存形态被移除。无公开 API 删除。