Repository navigation
fix(executor): reset inherited traps in builtin pipeline elements (Refs #3409) - #3617
Merged
Merged
Conversation
#3409) A builtin pipeline element ran in a subshell clone whose trap table was never reset, so the parent's live EXIT action fired at the element's teardown and again at shell exit. The compound and function stages already reset at entry; the builtin stage missed it. GNU disarms the EXIT trap in the forked element child (execute_cmd.c:4833 reset_signal_handlers, trap.c:1433 reset_or_restore_signal_handlers clears SIG_TRAPPED for EXIT_TRAP) while the element still runs its exit trap (shell.c:1054 subshell_exit runs run_exit_trap only if signal_is_trapped(0)), so a trap set inside the element re-arms and fires. 本 PR 删除了什么:无(纯加法修法:builtin 管道元入口补一次 reset_for_subshell_child 调用;无删除、无重命名、无行为面缩减)。 UNVERIFIED-BY-CAPTAIN
Member
Author
|
【WIN-AGENT-AUDIT】PR #3617 第1轮 — 建议:PASS(含 1 个 fmt 续作提交) 机制核查:
腿(逐项给数字与名字):
F 点:无(fmt 一处已在续作提交修掉)。 续作记录(本轮动过代码):
未跑/VOID 的腿:
|
caomengxuan666
marked this pull request as ready for review
November 16, 2026 12:04
This was referenced Nov 16, 2026
Closed
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.
Root cause
execute_builtin_pipeline_stage(src/executor/pipeline_stages.rs) clones a subshell executor for a builtin pipeline element and runs the subshell's EXIT trap at teardown (run_exit_trap_for_status), but — unlike its compound and function siblings, which both callreset_for_subshell_childat entry — it never reset the inherited trap table. The parent's live EXIT action therefore fired inside the element and again at shell exit:trap 'echo bye' EXIT; type ls | catprintedbyetwice.Fix
One call at the builtin stage's subshell setup:
reset_for_subshell_child(&mut subshell.shell_state.env_vars), mirroring the compound (pipeline_stages.rs:266) and function (pipeline_stages.rs:674) stages. A trap set INSIDE the element still re-arms throughset_trapand fires at the element's exit.GNU anchor
reset_or_restore_signal_handlers— clears SIG_TRAPPED for EXIT_TRAP first (trap string kept under reset).reset_signal_handlers()in the already-forked simple-command child (execute_simple_command, 4468), beforeexecute_subshell_builtin_or_function(4847).subshell_exit— runsrun_exit_traponlyif (signal_is_trapped (0)), so the disarmed inherited trap stays silent while an element-installed trap fires.execute_in_subshell(1576) for compound/( )elements.Oracle (GNU bash 5.3.20,
-cscripts): parent EXIT trap prints exactly once in every pinned shape; a trap set inside a( )element fires once at the element's exit and the parent's once at shell exit.本 PR 删除了什么
无(纯加法修法:builtin 管道元入口补一次
reset_for_subshell_child调用;无删除、无重命名、无行为面缩减)。Verification
UNVERIFIED-BY-CAPTAIN
( ), comsub, trap-inside-element, lastpipe).Refs #3409