Repository navigation
fix(executor): kernel-dup the [[ ]] stdio save (Refs #3730) - #3742
Merged
Merged
Conversation
The [[ ]] stdio save only cloned the userspace FdEntry, so the bind-time retire (retire_write_arm, rubash#3213) closed the very descriptor the restore was about to replay, and the next write or spawn's pin pass used whatever kernel descriptor had recycled that number (fd 1 lands on the [[ ]] redirect's target file, or the write is lost with EBADF). GNU's undoable redirect saves the displaced descriptor BEFORE the redirect binds, with fcntl (fd, F_DUPFD, SHELL_FD_BASE) (redir.c:965/1082/1144; SHELL_FD_BASE is 10, redir.c:86), recorded by add_undo_redirect for undo_redirections (the conditional stamps its line only once its redirections have bound, execute_cmd.c:4138 SET_LINE_NUMBER). This makes the scope save the same kernel dup: FdTable::saved_entry duplicates every File-backed endpoint (FileFd::duplicate, F_DUPFD_CLOEXEC on unix, non-inheritable duplicate on Windows), applied at the [[ ]] stdio save site — the same helper #3723 adds for the group redirect face (rubash#3706), ported here because that PR is still unmerged. A <> pair's two arms share one Rc; the save preserves that sharing so closing one direction still retires the shared descriptor, as GNU's close(2) closes the whole descriptor. A dup failure fails the command (GNU REDIRECTION_ERROR) via ?. The hazard needs fd 1/2 File-backed (at birth they are the symbolic Stdout/Stderr markers, which no retire touches), so the pin first runs exec 1>file / exec 2>file. Regression pin: tests/issue3730_cond_stdio_fd_restore.rs (10 cells: fd 1 output redirect, fd 2 stderr redirect, close form, LOOP form, 2>&1 dup form, both-slots form, offset-sharing guard, && list form, plain-conditional control, Linux-only external-child /proc face). UNVERIFIED-BY-CAPTAIN: no build slot was available (Simular box hibernated, X299 unreachable, local builds forbidden), so the pin's fail-first run and the verification legs are owed; see the PR body.
Member
Author
|
【WIN-AGENT-AUDIT】PR #3742 — 跳过(不合,不改代码) 处置:按本波规程「DIRTY/CONFLICTING → 跳过不合,报告」,本轮不做全腿审计、不 rebase、不关单。 备注:
|
Member
Author
fd_table.rs helpers already landed via #3739; take master's version (the PR's hunk was byte-identical modulo doc comments).
Member
Author
Member
Author
|
【WIN-AGENT-AUDIT】PR #3742 第3轮 — 建议:PASS 机制核查:
腿(逐项数字):
F 点:无。 续作记录:
未跑/VOID 的腿:无。 |
Member
Author
|
【WIN-AGENT-AUDIT】V 波批次汇总(v3 车道:#3742 / #3741 / #3740 / #3737 / #3734)— 核于 2026-11-17 10:15 CST
阻塞项 / 待队长裁定:
本 lane 未合入/未批准/未关闭任何 PR 或 issue;三条 draft 均为建议判词,等队长终审。 |
caomengxuan666
marked this pull request as ready for review
November 17, 2026 02:18
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 #3730.
根因
execute_conditional_command_with_redirects(src/executor/command_prepare.rs:386-387)的 scope save 只 Rc-clone userspaceFdEntry,随后bind_conditional_stdio_redirects绑定 fd 1/2 时 retire 被顶掉的 File 端点(retire_write_arm,rubash#3213)——bind 关闭的正是 save 打算恢复的那个描述符,两处 restore 循环把 retired entry 重新插回表内,下一次写或 spawn 的 pin pass 就 dup2 了内核已回收该号的描述符(fd 1 落到[[ ]]重定向的目标文件上,或写操作 EBADF 丢失)。与 #3706(group 面,#3723 修)同一 hazard,在条件命令 stdio 面。GNU 锚点:
execute_cmd.c:4138SET_LINE_NUMBER (cond_command->line)(条件命令只在自身重定向绑定成功后才 stamp 行号);redir.c:965/1082/1144fcntl (fd, F_DUPFD, SHELL_FD_BASE)(SHELL_FD_BASE=10,redir.c:86),由add_undo_redirect登记供undo_redirectionsdup 回去——undo save 本身就是内核 dup。修法
src/executor/command_prepare.rs:save 改为FdTable::saved_entry(1)?/(2)?(dup 失败即命令失败,对应 GNU REDIRECTION_ERROR;只用?,避开 fix(executor): restore fd N after group redirect (Refs #3706) #3723 返工修过的 E0308 坑)。src/executor/fd_table.rs(+111 行):新增FileFd::duplicate()(unix F_DUPFD_CLOEXEC;Windows 非继承 duplicate)、FdEntry::dup_file_endpoints()、FdTable::saved_entry()——与 fix(executor): restore fd N after group redirect (Refs #3706) #3723 的 helper 逐字一致的移植(fix(executor): restore fd N after group redirect (Refs #3706) #3723 仍未合入;若它先合,本 PR rebase 去重,只留站点改动)。<>对的两臂共享一个 Rc,save 保留共享语义。exec 1>file之后);钉的 cell 均先 exec 打底。src/lexer/continuation.rs;无新公开面(均为pub(crate)),未改docs/api-ledger.md。回归钉
tests/issue3730_cond_stdio_fd_restore.rs(10 cells):fd 1 输出重定向、fd 2 stderr 重定向、close 形式、LOOP 形式、2>&1dup 形式、双槽形式、offset 共享 guard、&&列表形式、无重定向 control、Linux-only 外部子进程 /proc 面。除 control 外全部 fail-first 设计。本 PR 删除了什么
未删除任何功能、测试、公开 API 或文档。仅删除两行裸 clone save(被 kernel-dup save 替代)。
UNVERIFIED-BY-CAPTAIN
构建路线全断(Simular box 钱包空 hibernated、X299 与老服务器同断、本 VM 禁本地构建),以下腿全部 OWED,由队长/Win-agent 在路线恢复后补跑:钉 fail-first(base 上红)、钉修后绿(10 cells)、全量 lib 双边、
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、GNU 对照探针、邻茎。已绿:rustfmt --check(三文件)、hygiene 脚本(check-marker-literals.py OK;check-utf8-boundary-hygiene.sh clean)、git diff --check、完整 staged diff 人工通读。
REPORT:
~/workspace/fix-3730/REPORT.md(不入仓)。守卫
(of$(to the case-word tracker in comsub walkers (Refs #3605) #3696/fix(heredoc): expand heredoc bodies on wordless null commands (Refs #2761) #3715 皆仍 OPEN、头未动,hunks 与本站点不同函数、最近 467 行,无重叠;heredoc: bodies on raw-empty null commands are never expanded (empty-words dispatch bypass) #2761 heredoc 面未碰。complete -F/-C路径(job_builtins.rs:5389)整表 clone + bind 存在同类 hazard,请队长立案;bind-error 路径不恢复为既存行为,另立单候选。