Skip to content

WIP: signal-death residuals — EXIT trap entry status (#2352) + ancestor-lane SIG_DFL death (#2353) - #2371

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/r5-signal-death-residuals
Oct 31, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/r5-signal-death-residuals

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2352
Refs #2353

Audit-wave residuals from PR #2351, two commits, GNU bash 5.3 source-first (clean-room: behavior facts only).

#2352 — EXIT trap entry $? on signal death (commit e4d1666)

GNU: sig.c:590 termsig_handler → run_exit_trap() (sig.c:644) → kill_shell(sig) (sig.c:646); nothing rewrites last_command_exit_value to 128+sig — trap.c:1036 saves it as the trap's entry $?. 128+sig is child wait-status translation only (jobs.c:2961).

  • Capture the pre-signal status at both death-mark points before the 128+sig overwrite (boundary note + hangup-drain classification). At a boundary / blocked-wait drain it equals the last completed command's status (an interrupted wait never commits).
  • Ancestor lane: the carrier commits before dispatch, so the parent's pre-carrier value is snapshotted at queue time — execute_kill arms the status it started with (the kill builtin completes before dispatch; direct deliveries therefore capture its own 0), queue_ancestor_signal stamps it on the entry, and the dispatch overrides the capture for ancestor entries.
  • finish_shell consumes the capture with the mark; the capture parks/restores across contained-child spans with the mark ([bug] 致命信号死亡形态:EXIT trap 照跑,但以 128+n 退出而非被信号杀死 TERM/INT/USR1(审计 RC3) #2346 discipline).

#2353 — ancestor lane, no EXIT trap, non-interactive (commit 96113da)

Verification

  • 32-cell script-file probe matrix (waitpid-adjudicated — shell $? cannot distinguish signaled death from 128+n) against GNU bash 5.3.20: 31/32 byte-exact. The one non-exact cell (ancestor SIGINT + EXIT trap) is racy in GNU itself across identical runs (signaled 2 twice, SURVIVED once — arrival before vs during the parent's wait); rubash deterministically takes the termsig outcome, consistent with [bug] 致命信号死亡形态:EXIT trap 照跑,但以 128+n 退出而非被信号杀死 TERM/INT/USR1(审计 RC3) #2346. The no-trap ancestor SIGINT cell takes the documented wait-absorb outcome (jobs.c:2908; GNU majority in sampling). Both races are recorded in the cluster report, not papered over.
  • New pins: issue2352_exit_trap_status_regressions 8/8, issue2353_ancestor_lane_termsig_regressions 13/13.
  • Neighbor families re-run, zero regressions: issue2346 11/11, issue2236 9/9, issue1331_1334 7/7, issue1853 6/6, issue1035_1036 11/11, issue1043_1054 7/7, issue1990_1991 19/19, issue2241 5/5, issue526 1/1, issue1493 2/2, issue1997 4/4.
  • cargo check clean, 0 warnings; touched files rustfmt-clean; src/lexer/continuation.rs NOT touched.

Known residual boundary

Ancestor snapshot layer corner: if the sending layer runs status-changing commands before its kill (e.g. (exit 7) then ( false; kill -TERM $$ )), the snapshot is the layer's last-completed status where GNU's preempted parent keeps the pre-outermost-carrier one (the layer's commands run in a child). Exact capture needs a layer-entry snapshot hook the layer machinery does not have; the bare-carrier shapes the issues mandate are exact. Recorded in the cluster report.

caomengxuan666 and others added 3 commits October 31, 2026 14:42
…eath

GNU: sig.c:590 termsig_handler() calls run_exit_trap() (sig.c:644)
then kill_shell(sig) (sig.c:646); nothing on that path rewrites
last_command_exit_value to 128+sig — trap.c:1036 run_exit_trap saves
last_command_exit_value as the trap's entry $?. The 128+sig synthesis
belongs to child wait-status translation only (jobs.c:2961).

Captured at both death-mark points (boundary note + hangup drain
classification) BEFORE the 128+sig overwrite: at a boundary the value
is the last completed command's status; at a blocked-wait drain it is
likewise the last completed command (the interrupted wait never
commits). The ancestor lane delivers after its carrier construct
committed, so the parent's pre-carrier value is snapshotted at queue
time instead: execute_kill arms the status it started with (the kill
builtin completes before dispatch, so its own 0 is the value for
direct deliveries) and queue_ancestor_signal stamps it on the entry;
the dispatch overrides the capture with the sender snapshot for
ancestor entries. finish_shell consumes the capture together with
the death mark and runs the EXIT trap with it. The capture parks and
restores with the mark across contained-child spans
(external_finish), matching the #2346 discipline.

Refs #2352
…IT trap

A #1654 routed delivery is synthetic — no kernel disposition ever
fires for it — so the boundary dispatch enacts the addressed shell's
verdict itself. GNU's matrix for the untrapped cell: with no EXIT
trap in a non-interactive shell, initialize_terminating_signals
never installs a terminating handler (sig.c:230-236 — it runs for
non-interactive shells only when an EXIT trap is defined), so the
delivery stays at SIG_DFL and the shell dies BY the signal.
note_routed_untrapped_termsig arms the same termsig-death mark for
that cell (signal in the exit_reroutes terminating set,
non-interactive, no contained-child route — a contained child's
death is the simulated adjudicated record, rubash#2236).

SIGINT is the exception and is absorbed, not armed: while a script
shell waits for a foreground job, wait_sigint_handler (jobs.c:2908)
records the delivery and otherwise ignores it; the shell dies of
SIGINT only when the job itself died of it (jobs.c:4384, 4410
child_caught_sigint). The lane's carrier completed normally by
construction — the entry surfaces only after the carrier exits — so
the dispatch drops the entry and the carrier's status stands.
Kernel-lane entries are untouched (their stale check proves a
handler story this lane never has), as are interactive shells
(DISCARD classification, rubash#1662).

Refs #2353
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 16:02
@caomengxuan666
caomengxuan666 merged commit cf61549 into master Oct 31, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/r5-signal-death-residuals branch November 2, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant