Repository navigation
fix(executor): restore fd N after loop heredoc (Refs #3725) - #3737
Merged
Merged
Conversation
execute_simple_loop saved the displaced fd with a bare Rc clone, then open_input retired the descriptor the clone shared, so the post-loop restore re-inserted a retired entry (the #3706 hazard, loop-heredoc face). Save via FdTable::saved_entry — a kernel dup of the displaced descriptor, the same undo-save #3723 introduced for group redirects — and unwind already-bound heredocs if the dup fails (GNU undo_partial_redirects, execute_cmd.c:855). GNU: loop redirections are undoable (execute_cmd.c:854 do_redirections RX_ACTIVE|RX_UNDOABLE); the undo save is fcntl(fd, F_DUPFD, SHELL_FD_BASE) (redir.c:965/1082/1144). New pins: tests/issue3725_loop_heredoc_fd_restore.rs (6 cells). UNVERIFIED-BY-CAPTAIN: all cargo legs owed, routes down.
This was referenced Nov 15, 2026
Member
Author
|
【WIN-AGENT-AUDIT】PR #3737 第1轮 — 建议:FAIL 机制核查:
腿:
F 点:
续作记录:
未跑/VOID 的腿:无(关键腿均已跑,结论为负)。 |
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.
根因
execute_simple_loop(src/executor/alias_loops.rs)在绑定 loop heredoc 前用裸Rcclone 保存被顶掉的 fd 条目,随后open_input的绑定 retire(close)了该 clone 共享的内核描述符(rubash#3213),循环结束后的 restore 又把 retired entry 插回表里——下一次read <&N读到 EBADF 或错误目标。这是 #3706 同一 hazard 的 loop-heredoc 面(#3723 修的是 group redirect 面)。修法
FdTable::saved_entry:对被顶掉的描述符做内核 dup 快照(与 fix(executor): restore fd N after group redirect (Refs #3706) #3723 同一 undo-save),restore 回放的是活的 duplicate 而非 retired entry。undo_partial_redirects),再以ExecuteError::IoError上报,调用方永不见半绑列表。restore_loop_heredoc_fd_inputs,post-loop restore 与 dup 失败 unwind 共用。fd_table.rs的三个 helper(FileFd::duplicate/FdEntry::dup_file_endpoints/FdTable::saved_entry)与 fix(executor): restore fd N after group redirect (Refs #3706) #3723 的实现逐字节相同(fix(executor): restore fd N after group redirect (Refs #3706) #3723 尚未合入,本 PR 需自带才能独立编译)。定序提示:若 fix(executor): restore fd N after group redirect (Refs #3706) #3723 先合入,本 PR rebase 时丢掉fd_table.rs部分即可;若本 PR 先合,fix(executor): restore fd N after group redirect (Refs #3706) #3723 同理。GNU 锚点
execute_cmd.c:854 do_redirections (command->redirects, RX_ACTIVE|RX_UNDOABLE);失败 unwind:execute_cmd.c:855 undo_partial_redirects ()。redir.c:965/1082/1144 fcntl (fd, F_DUPFD, SHELL_FD_BASE)。third_party/bash(Bash-5.3 patch 20,9c465866)上核实。回归钉
tests/issue3725_loop_heredoc_fd_restore.rs(6 cell):fd 8 主元、fd 3 变体、body 内读 heredoc + 恢复、until 变体、两次循环共享 offset 连续读、无 heredoc 对照(对照在未修基底上亦绿)。本 PR 删除了什么
什么也没删除。纯加法:fd_table 增加 3 个 helper(+107 行),alias_loops 改保存 + 抽 restore helper(+49/−11 行),新增 1 个测试文件(+163 行)。无公开面新增,无行为删除。
验证状态
UNVERIFIED-BY-CAPTAIN:构建/验证路线当前全断(Simular box 钱包空 hibernated、X299 与老服务器同断、本 VM 无 cargo 且禁本地构建),以下腿全部 OWED,由队长/Win-agent 在路线恢复后补跑:钉 fail-first(基底红)、修后绿、邻茎、全量 lib 双边、
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、GNU 5.3 oracle 对照。已做:6 条期望输出在系统 bash 5.2.21 下作指示性核对(5.3 script-file oracle 亦 OWED);git diff --check通过;rustfmt 本机无工具链未跑。