Repository navigation
WIP: fix nested rubash child signal death killing the outer shell - #2248
Merged
Merged
Conversation
A same-shell script child runs in-process (execute_direct_shell_script), so when the child killed itself with an untrapped signal the delivery fell through to raise(2) on the hosting process and the OUTER shell died with the child's signal. GNU runs the child as its own process (execute_cmd.c:6139-6233): the kill can only kill the child, the parent observes 128+signal, prints the jobs.c foreground death notice, and continues. While a contained child runs, kill deliveries addressed to the process's own pid now join the ancestor lane instead of raising, so the child's own trap table adjudicates them (trapped: action runs, child continues; ignored: dropped; untrapped: only the child ends at 128+signal). For the span of the run the executor presents the child's fresh-process identity (shell_pid = the process pid, subshell depth 0), an exit drain adjudicates a delivery that arrived as the child's last command, and an adjudicated death is recorded so the exit boundary can queue the parent's death notice for the child. ENOEXEC children keep the historical fork-child model untouched. Regression pins: tests/issue2236_nested_signal_death_regressions.rs (9 pins, GNU bash 5.3.20 oracle; the five untrapped-death pins are red on master bbd95e3). Refs #2236
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 #2236
Problem
A nested rubash child that kills itself with an untrapped signal took the outer shell down with it: outer died by the same signal, no
inner-rc, no further commands. GNU (all four outer/inner arms probed byte-wise) reportsinner-rc=143, prints the foreground death notice (Terminated <child argv>), and continues. The divergence existed only for rubash×rubash nesting.Mechanism
execute_direct_shell_scriptruns a same-shell script child in-process on the parent's Executor (no second execve — strace-verified). The child'skill -TERM $$therefore addressed the hosting process: the ancestor route (#1654) is armed only for flat subshell layers (subshell_depth > 0), so the delivery fell through tolibc::raiseand killed the outer shell. Two sibling shapes compounded it: in a subshell host the child inherited the adopted outershell_pid, so its$$named the outer process and the suicide escaped as a real kill(2); and a delivery queued as the child's last command was left for the parent's boundary poll (or the fresh-shell exit discard).Fix
src/builtins/kill.rs: newDIRECT_CHILD_ROUTEthread-local (RAII arm, sibling ofANCESTOR_ROUTE). While armed, a kill delivery to the process's own pid joins the ancestor lane (ANCESTOR_SIGNALS) — the lane whose contract is "no kernel-disposition judge, adjudicated by the then-current trap table". The plain self-signal queue would be wrong: its entries carry the stale-handler check, and an untrapped signal has no kernel handler by design ([linux] Blocked rubash is unkillable by SIGTERM: signal_hook installs with SA_RESTART and pending signals dispatch only at command boundaries #226). Plus an adjudicated-death record (ADJUDICATED_SIGNAL_DEATH) written by both untrapped adjudication funnels.src/executor/trap_exec.rs:run_pending_signal_trapsandobserve_signals_while_blockedrecord an untrapped 128+signal verdict into the death record.src/executor/external_finish.rs:execute_direct_shell_scriptgainscontain_child_signals(true for the THIS_SH/script and same-shell-binary entries; false for ENOEXEC, which keeps the historical fork-child model). For the span of a contained run: the route is armed,shell_pidpresents as the process pid and subshell depth as 0 (the child's fresh-process identity; the tail already restores both), the notice text is captured pre-run, an exit drain adjudicates a last-command delivery at child depth 0, and if the adjudicated death is the final status the parent queues the jobs.c death notice via the existingnote_child_signal_death.GNU grounding: child-as-own-process (execute_cmd.c:6139-6233), boundary adjudication by the current trap table (trap.c run_pending_traps), foreground death notice (jobs.c).
Verification (GNU bash 5.3.20 oracle, debug build of this branch)
-c— all byte-identical to GNU (pipeline modulo a pre-existing PIPESTATUS race that also reproduces with a plain echo script and a GNU stage; noted in the cluster REPORT).kill -0/kill -linside a child; three-level nesting; an external SIGTERM to a waiting outer still kills it (no containment leak).tests/issue2236_nested_signal_death_regressions.rs: 9/9 green on this branch; on master the five untrapped-death pins are red, the four guard pins (trapped/ignored/-c/single-layer) already green.Full gate via PR CI per cluster discipline.