Repository navigation
Refs #2763: consume heredoc-body funsub exit latch at the carrying command - #3474
Merged
Merged
Conversation
…mmand
A ${ ...; exit N; } funsub inside a heredoc body latches
current_shell_substitution_exit, whose only consumer ran after word
expansion — before the heredoc pre-expansion — so the latch lingered
and surfaced in the NEXT command. Consume it at the GNU
do_redirections point (redir.c:348), right after preexpand_command_stdin:
- main-shell target (builtin/function, execute_cmd.c:5606): abort the
shell with N; the command never runs (GNU probes A/C: nothing after
prints, rc 42).
- forked target (disk command, execute_cmd.c:5522): the child dies
with N during do_redirections before exec (GNU probe G: cat never
prints the body's hello), so the command never runs and N is its
status; the script continues (GNU probe B: status=42, next runs).
preexpand_command_stdin now returns what the forked child latched
(the fork boundary restores exit code/bookkeeping but not the latch);
with_forked_heredoc_expansion itself is untouched. Regression pins in
tests/issue2763_heredoc_funsub_exit_latch.rs (6 tests).
UNVERIFIED-BY-CAPTAIN: no build or test run this round (no build slot
available); legs owed to the captain review round.
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项给数字与名字):
F 点:
未跑/VOID 的腿:
|
…s status (Refs #2763) GNU basis: execute_cmd.c:2620 execute_pipeline forks EVERY element (including builtin-shaped ones), and redir.c:348 do_redirections runs inside that child — so a `${ ...; exit N; }` funsub in a pipeline element's heredoc kills the element's own child, contributes status N to the pipeline, and never reaches the main shell (unlike the bare builtin asymmetry of execute_cmd.c:5606). Rubash expanded stage 0's stdin bodies on the parent executor inside initial_pipeline_input, so the latch surfaced at the NEXT command's word-expansion consumer as a shell abort — the pin observed `F1-before\n\n` then rc=42 while GNU prints `F2-after status=0 pipe=42 0` and continues. initial_pipeline_input now runs the body expansion inside with_forked_heredoc_expansion (the same in-process fork emulation execute_disk_command's heredoc pre-expansion uses) and reports a latched funsub exit via a new out-param. The sequential stage loop records the death as the element's status with an empty stream — the same shape as the existing debug-trap element skip — and every concurrent driver (all-external, shell-writer, prefix, streaming tail, sandwich) declines on the verdict so the sequential loop owns it, per the whitelist-decline rule. Non-fd-0 heredoc bodies for pipeline stages keep their existing expansion path (residual). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Member
Author
|
【WIN-AGENT-REWORK】round 2 — head F 点逐条回应
跑腿结果
|
caomengxuan666
marked this pull request as ready for review
November 15, 2026 06:05
This was referenced Nov 15, 2026
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.
根因
${ ...; exit N; }funsub 在 heredoc 体内触发时,current_shell_substitution_exit被 latch(src/executor/embedded_mutations.rs:2216),而唯一的消费点在词展开之后、heredoc 预展开之前(command_execute.rs:378),于是 latch 滞留、在下一条命令才冒出来。修复前探针 B 的表现:B1之后什么都不打印,echo B2被偷来的 latch 以 42 中止。GNU 锚点
redir.c:348heredoc_expand:体在命令的 do_redirections 里展开。execute_cmd.c:5606execute_builtin_or_function:内建/函数目标在当前 shell 做重定向——funsubexit以 N 中止整个 shell(探针 A/C:read/:之后无输出,rc 42)。execute_cmd.c:5522execute_disk_command:磁盘命令先 fork、子进程做重定向——子进程在 do_redirections 期间以 N 死亡、命令根本不 exec(探针 G:cat从不打印体内的hello),N 成为命令状态、脚本继续(探针 B:B2 status=42,B3照跑)。subst.c:7101nofork comsubparse_and_execute。以上均以 GNU bash 5.3.20 脚本探针复核(工作区
probes/GNU-RESULTS.md,A–D + 机制探针 E–H)。改动
仅
src/executor/command_execute.rs:preexpand_command_stdin返回Option<i32>:fork 分支在 fork 边界内外保存/恢复父 latch,只带回子进程 latch 的值(with_forked_heredoc_expansion本身未动,其另两个调用点不在本次范围)。exit_code = N+Err(ExitCode(N))(命令不跑,壳以 N 退出);fork latch →exit_code = N+Ok(())(命令不跑,N 为命令状态,继续跑)。主 shell latch 在abort_on_expansion_errors()之前就取走,防止算术错误早退路径再次泄漏。tests/issue2763_heredoc_funsub_exit_latch.rs(6 个用例:A/B/C/D/G/F)。本 PR 删除了什么
无。只改了一处消费点 + 一个返回值,未删任何公开面、测试或文档。
UNVERIFIED-BY-CAPTAIN
本轮无任何构建/测试运行:本地构建禁(写墙)、Simular box 满盘、老服务器 ssh 未恢复、X299 未直连。以下腿留队长复核轮(X299):
cargo test --locked --test issue2763_heredoc_funsub_exit_latch(先--bin rubash)、全量 lib 与 base 逐数对齐、RUSTFLAGS="-D warnings" cargo check --locked --lib --bins。Fail-first 为代码推导(见钉文件头),复核轮须在 base 上确认红、在 head 上确认绿。已知残差(REPORT 有 GNU 证据):裸 heredoc(无命令词)GNU 一律折成状态 1,属
execute_empty_words_command的另一条路,未修;heredoc 之前的重定向副作用(cat > /tmp/out <<EOF仍建文件)本轮跳过派发故未复现。Refs #2763