Repository navigation
fix(executor): let a live fd-0 File endpoint outrank the FUNCTION_STDIN mirror in exec spawns (Refs #3046) - #3461
Conversation
…IN mirror in exec spawns (Refs #3046) Root cause: `exec_inherited_stdin` consulted the FUNCTION_STDIN mirror before the fd table. The text channel deliberately declines character devices (shell_options.rs stdin_string_for_command: a device has no EOF to slurp, "the caller binds the live fd instead"), and execute_exec's bind_command_fd0_input does bind that live FileFd — but the mirror arm fired first, so a stage-0 mirror (empty: no producer) handed the child Stdio::null() (0 bytes), and a later stage's mirror handed it the upstream pipe bytes (`echo hi | exec dd </dev/urandom` read "hi\n"), shadowing the redirect the shell had just bound. A regular file only "worked" because the text channel slurped its content into the mirror; the child read the mirror, not the fd. GNU anchors (vendored bash 5.3.20): - execute_cmd.c:5520-5522 (execute_subshell_builtin_or_function): do_piping first, then do_redirections (redirects, RX_ACTIVE) — the element's own redirect replaces the pipe on fd 0. - execute_cmd.c:6375 do_piping: dup2 (pipe_in, 0). - builtins/exec.def:231: shell_execve replaces the image with the descriptors as bound. - redir.c:725 redir_open: the target is opened uniformly; the file TYPE of the stdin target is never consulted. Fix: resolve a live fd-table File/CoprocStdout endpoint on slot 0 before the FUNCTION_STDIN mirror — the precedence the codebase already states in function_stdin_is_command_source ("the mirror is fd 0's binding only while fd 0 itself is unbound") and in stdin_string_for_command's tail ("an exec-installed fd 0 in the fd table shadows the ambient FUNCTION_STDIN buffer"). The bind's text branch removes the fd-table entry when it stages text, so no stale File endpoint can coexist with a text mirror from the same bind. Nails: tests/issue3046_exec_pipeline_chardev_stdin.rs (15 cells, already on master via #3173) — stdin urandom/head/zero, controls, stderr devnull/file, subshell, chain, comsub mktemp-style chain, top-level contrasts, stdout-to-file exception. No new test file. 本 PR 删除了什么:无。仅调整 `exec_inherited_stdin` 内两个分支的 求值顺序(File 臂移至 FUNCTION_STDIN 镜像臂之前),无函数、无文 件、无公开面的增删。 UNVERIFIED-BY-CAPTAIN
…in's endpoint match (Refs #3046) Rework of f2bae8f: CI was red on a single E0004 (non-exhaustive patterns) at trap_exec.rs:4538 — the trailing match on fd_table.read_endpoint(0) had no arms for File / CoprocStdout. Both arms bind the live fd exactly as the early return above does (duplicate_handle_inheritable + handle_to_file), the same shape as open_fd_read_endpoint_stream (shell_options.rs:1182/1194); no wildcard, no semantic change. GNU anchor unchanged (REPORT §2: execute_cmd.c:5520-5522, builtins/exec.def:231, redir.c:725).
|
【WIN-AGENT-AUDIT】 PR #3461 第1轮 — 建议:PENDING(缺腿) 机制核查:
腿(逐项):
F 点:无。 续作记录:未动代码。 未跑/VOID 的腿:
|
|
【WIN-AGENT-REWORK】 PR #3461 第2轮 — 建议:PASS(缺腿补齐) 本轮补腿(WSL Linux /root/rubash-wsl,CARGO_INCREMENTAL=0,cargo test --locked -j 2):
未动代码;其余腿按第1轮审计记录全绿。判词翻 PASS,按协议 squash 合并。 |
|
【WIN-AGENT-REWORK】批次汇总(L 波 12 项,终报存 final-report-rework-l.md) 已合并 10:#3461 c2a5800|#3596 cac7a13(解锁链)|#3486 5dcd1e6|#3480 f72b5c2|#3439 b7c3af5|#3438 27d3483|#3463 fc574f5|#3375 83e2fe7(fork 三轮叠加:PwdOutcome comsub 调用点 + FileFd.closed 两字面量 + 再 merge master,终头 CI 红全 = issue2875 基线)|#3600 7353ef7|#3589 e527da1(niubash 镜像 0c8d81e 配对补齐)|#3166 016db15(bats-core 树到位,cell A 实跑为缺陷复现) 未合并 1:#3554 判词 PASS、腿全绿(unix 钉 4/4 + base overlay 0/4 + 两残差疑点与 GNU 逐字节一致),mergeState=DIRTY 文本冲突(hash.rs/lookup_paths.rs/path.rs)——按协议未解冲突,待 owner 处理后即合。 遗留观察(非阻塞):#3375 复核发现 renamed-cwd 下 |
|
【WIN-AGENT-ISSUE-CLOSE】批次汇总(lane C:本轮新合并 PR 关联 issue 补关,终报存 final-report-close-c.md) 已关 12:rubash#3420←#3438|#2777←#3463|#3397←#3471|#3213←#3473|#2763←#3474|#3267←#3475|#2769←#3480|#3299←#3482|#3448←#3486|#3572+#3571←#3589(§5 文案同 PR 顺带修,niubash 镜像已配对)|niubash#879←#1009(五主题裁定=harness 侧,按 issue 裁定路径完成) 已关跳过 10:#3093 #3349 #3353 #3046 #3425 #3359 #2875 #3542 #3430 #3573 不关 8:rubash#3049 #3091(#3166 纯钉、缺陷 live)|#3026 #3032 #3048(#3169 纯钉、缺陷 live)|niubash#955(跨仓对应项,rubash PR 不可交付)|niubash#993(#998 只落 §8/§11/§12 三面)|niubash#731(K3 多项工单,#1011 仅交付钉,范围 1/4 未落地) 口径备注:squash SHA 取 mergeCommit.oid 前 7(同 close-A/B);清单 7 条所给前缀为 head SHA 已更正(#3461/#3473/#3480/#3486/#3554/#3588/#3593)。无留置项。 |
根因
exec_inherited_stdin(src/executor/trap_exec.rs)先查 FUNCTION_STDIN 镜像、后查 fd 表。文本通道对字符设备故意 decline(shell_options.rsstdin_string_for_command:设备无 EOF 可 slurp,"the caller binds the live fd instead"),且execute_exec的bind_command_fd0_input也确实绑了 live FileFd;但镜像臂先到:stage-0 镜像为空 → 孩子得Stdio::null()(0 字节);后级 stage 镜像为上游 pipe 字节 → 孩子读 pipe(echo hi | exec dd </dev/urandom读到 "hi\n")。普通文件"正常"只是假象——文本通道把文件内容 slurp 进镜像,孩子读的是镜像而非 fd。GNU 锚点(vendored bash 5.3.20)
execute_cmd.c:5520-5522(execute_subshell_builtin_or_function):do_piping在先、do_redirections (redirects, RX_ACTIVE)在后——元素自己的重定向覆盖 pipe 的 fd 0execute_cmd.c:6375do_piping:dup2 (pipe_in, 0)builtins/exec.def:231:shell_execve以已绑定的描述符替换镜像redir.c:725redir_open:目标统一 open,文件类型从不参与修法
exec_inherited_stdin内:live fd-table File/CoprocStdout 端点先于 FUNCTION_STDIN 镜像解析——与库内既定优先序一致(function_stdin_is_command_source:镜像仅当 fd 0 自身未绑定时才是 fd 0 的绑定;stdin_string_for_command尾部:"an exec-installed fd 0 in the fd table shadows the ambient FUNCTION_STDIN buffer")。bind 的文本分支在 stage 文本时移除 fd 表项,故同一 bind 装的文本镜像旁不可能有 stale File 端点。钉
tests/issue3046_exec_pipeline_chardev_stdin.rs(15 格,master 已有,#3173):stdin urandom/head/zero、对照、stderr devnull/文件、subshell、chain、comsub mktemp 链、top-level 对照、stdout-to-file 诚实例外。本 PR 不新增钉文件。证据
printf 'ABCDE' | exec dd bs=10 </dev/urandomrubash 5 / GNU 10;echo hi | exec dd </dev/urandomrubash 3 / GNU 10;subshell 面 rubash 正常;stderr 面在 Nov-10 二进制上已不复现(应为区间提交 d4f7d94 + a0c4644 已修,须头上以钉复核)~/workspace/fix-3046/REPORT.md本 PR 删除了什么
无。仅调整
exec_inherited_stdin内两个分支的求值顺序(File 臂移至 FUNCTION_STDIN 镜像臂之前),无函数、无文件、无公开面的增删。UNVERIFIED-BY-CAPTAIN
返工(2026-11-13,头 ae6b2f1)
error[E0004]: non-exhaustive patterns(src/executor/trap_exec.rs:4538:15):exec_inherited_stdin尾部的match self.fd_table.read_endpoint(0)缺File/CoprocStdout两臂。open_fd_read_endpoint_stream(shell_options.rs:1182/1194)一致;无通配臂、无语义改动。rustfmt --check已清;验证腿(cargo check、钉 15 格双边、GNU 三方探针、lib 双边、-D warnings、hygiene、终头 CI)由盒驱动回填中,详见~/workspace/fix-3046/REPORT.md§7–§8。UNVERIFIED-BY-CAPTAIN