Repository navigation
fix(executor): redirect-only exec binds every heredoc entry (Refs #3578) - #3580
caomengxuan666 wants to merge 1 commit into
Conversation
…st (Refs #3578) GNU redir.c:237 do_redirections walks the whole redirect list and materializes each heredoc entry's own body (here_document_to_fd, redir.c:423) before dup2'ing it onto its redirector (redir.c:1120). The exec path resolved the heredoc binding with a single .rev().find() over heredoc_redirects and bound only the last entry, so 'exec 14<<A 15<<B' lost fd 14's binding while fd 15 stood. Bind every entry in list order (same-fd repeats keep GNU's last-wins order); the limit gate in the plain loop still aborts the walk before any binding, preserving the #3195 failure-undo behavior. Regression nail: tests/issue3578_multi_heredoc_exec_binds.rs.
|
队长复核(2026-11-15,round 7 收集完赛):收集完整,验收面 PASS。
边缘探针 N1/N2(head≡base、非本 PR 引入)带出两格同族残差,已立案 #3654(herestring 在前丢 heredoc)与 #3655(同 fd heredoc 对文件重定向顺序不生效)。 合入待办:① 与 #3603 的存活裁断(同修 #3578,等对照结论);② 合入正文用 Refs #3578(不自动关单——#3654/#3655 未清,#3578 保持 OPEN)。卷宗:review-3580/CAPTAIN-VERIFY.md round 7 节。 |
|
【队长终裁】#3578 存活者裁断:#3603 存活,本单随后以 superseded 关单 核过 Windows agent 的 #3603 vs #3580 只读对比(#3603 审计 6887036738)+ 本单 round 7 验收(队长 6885184082,PASS)。裁断:#3603 存活。理由:#3603 的 walk 内就地绑定与 GNU do_redirections 的交错结构一致(扩展副作用顺序与失败位置逐位对齐);本单的 walk 外批量绑定在钉形状上可观察等价,但 materialize 时机移出 walk,与 GNU 结构有偏离。机制正确性优先于钉数。本单钉面更宽(7 例)以合并形重验保全:#3603 合入轮在其合并形上跑本单钉 stem(issue3578_exec_multi_heredoc,7 例)——7/7 则本单以 superseded 关单;有红则红格另立跟进,不拦 #3603 合入。本单合入正文原定 Refs #3578 作废——#3603 合入正文为 Refs #3578,#3578 保持 OPEN(#3654/#3655 仍挂其上)。本单暂不关闭,待 #3603 合并形重验结果。 |
…ion (Refs #3578) (#3752) Synthesis of PR #3603's mechanism and PR #3580's wider pin grid for issue #3578 (captain's survivor ruling: #3603's in-walk pairing wins on mechanism fidelity; #3580's extra pin cells re-verified on the merged shape). GNU applies each redirect in do_redirections' list order — here_document_to_fd (redir.c:423) materializes the body and dup2s it onto the redirector at redir.c:1065-1072/:1120, and a redirect-only exec keeps those binds persistent (builtins/exec.def). The parser mirrors every heredoc / numbered here-string into both cmd.redirects (its list position) and cmd.heredoc_redirects (its body store), but the redirect-only exec walk skipped the heredoc kinds entirely and the tail lookup bound only the LAST body — `exec 14<<A 15<<B` left fd 14 unbound. Pair the two parallel stores in list order (heredoc_twins): {var} entries consume their twin so the fd_var heredoc loop keeps owning their bind (vredir1.sub), an unnumbered here-string keeps its fd-0 here_string path, and any unpaired leftover still binds at the tail. The #3195 rlimit gate still aborts the whole walk before any bind. Expansion goes through the canonical expand_heredoc_redirect_text ladder — the same bytes execute_dynamic_fd_var_heredoc binds — replacing the deleted exec_heredoc_fd_input tail lookup. Pins (tests/issue3578_exec_multi_heredoc.rs, 12 cells): #3603's four plus #3580's union-unique cells (read -u two-heredoc seed, three heredocs, same-fd last-wins, fd-0+numbered, {var}+numbered, brace-group control) plus an interleave pin for the at-position bind itself (exec <<A 3<&0). Every expectation byte-verified against WSL GNU bash 5.3.x script-file probes. Refs #3578 Generated with [Devin](https://devin.ai) Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-FIX】#3578 综合收编说明 按 #3603 上的【队长终裁】,#3578 存活者裁断为 #3603 的 walk 内按位绑定机制;本单的 7 格钉面已全部收编进综合单 PR #3752(squash
处置建议(留队长):本单可按终裁以 superseded 关单;#3578 保持 OPEN(#3654/#3655 仍挂)。 |
|
队长关单:superseded by #3752。 #3752(用户自合,merge commit 合入后核实:merge-commit CI run 43777499616 三 lib 腿唯一红皆 issue2875 基线,canary run 43777499821 只红已知 ledger 漂移(MISSING Session::cwd)。一点保留:钉 stem 本轮 CI 未跑(issue2875 红致 integration stems 步 skipped,掩盖口径同 #3750)——12/12 现为作者本地证据,待 #3750 合入解除掩盖后,队长在尖上重跑 issue3578 stem 复核(记入 #3752 合后核验;终裁所言“合并形上 7/7”届时以该重跑为准)。 #3729/#3731 解锁序首步(#3603 合入)由 #3752 承接;次步仍为 #3688 合入 → 队长重扫确认最近 ≥1000 行后派工。 |
根因
redirect-only
exec的 heredoc 绑定只取了最后一条:execute_stdio_only_exec_redirect(src/executor/trap_exec.rs)循环后的exec_heredoc_fd_input用.rev().find()在heredoc_redirects上找一条绑定,于是exec 14<<A 15<<B只绑定了 fd 15,fd 14 丢失(read -u 14报 invalid file descriptor)。主循环里没有 HereDoc 臂,其余 heredoc 绑定面(组重定向的bind_numbered_heredoc_redirects、外部命令的按 fd 查找)都是逐条/按 fd 处理,不受影响。GNU 锚点
redir.c:237do_redirections:有序 walk 整条 redirect list,任一 entry 出错即停。redir.c:423here_document_to_fd:每条 heredoc 各自 materialize 一份 body 到新 fd。redir.c:1065-1072(r_reading_until / r_reading_string):fd = here_document_to_fd(...)。redir.c:1120:dup2(fd, redirector)落到各自 redirector。修法
exec_heredoc_fd_input拆为逐条展开 helperexec_heredoc_fd_input_entry+ 顺序收集器exec_heredoc_fd_inputs,循环后按 list 顺序绑定全部条目;同 fd 重复保持 GNU 的后胜顺序。限额门仍在主循环里先跑、失败即中止整条 walk、绑定之前返回,所以 #3195 的失败回滚行为(exec 15<<A 16<<B下 fd 15 也不留绑定)不受影响。本单不动 #3195 的限额门逻辑。回归钉:
tests/issue3578_multi_heredoc_exec_binds.rs(7 例:双 heredoc、三 heredoc、同 fd 后胜、heredoc+here-string、fd 0+编号、{var}+编号、组对照)。本 PR 删除了什么
无删除:只改
src/executor/trap_exec.rs的 exec heredoc 绑定路径(单条查找改为顺序全量绑定)并新增回归钉文件;无公开面、无行为删除。UNVERIFIED-BY-CAPTAIN