Repository navigation
WIP: fix(signals): install handlers for trapped stop-class signals and SIGCONT - #2350
Merged
Merged
Conversation
…CONT (Refs #2344) The kernel-signal backend's managed set — the eligibility set for the rule that the trap table drives kernel dispositions — omitted exactly SIGTSTP/SIGTTIN/SIGTTOU/SIGCONT. Traps on them were recorded in the trap table (trap -p listed them) but no handler was ever installed: a trapped CONT was silently discarded, a trapped stop signal left the disposition at SIG_DFL so the shell really stopped and the trap was dropped on resume, and `trap '' TSTP` never installed SIG_IGN. GNU installs the deferring handler for ANY trapped signal: trap.c:838 set_signal -> sig.c:830 set_signal_handler (sa_flags=0), execution deferred through pending_traps[] to trap.c:328 run_pending_traps at a command boundary, so a trapped stop signal never stops the shell. Restore that invariant: - MANAGED_CORE and managed_trap_keys gain TSTP/TTIN/TTOU/CONT, so reconcile computes their wishes (trap -> handler, trap '' -> SIG_IGN, none/reset -> entry disposition) and the entry snapshot, fork-child restore, and boundary dispatch all see them. - exit_reroutes excludes the stop class and CONT: GNU's terminating set (sig.c:127 terminating_signals[]) names neither — their default actions are stop/resume, not termination — so an armed EXIT trap must not reroute an untrapped stop (oracle: the shell still stops, verified by /proc State evidence). - The in-process layer routes (ancestor/direct-child) keep the stop class + CONT non-adjudicable: those lanes synthesize death verdicts, and a stop/resume has no death verdict to synthesize. - sleep_interruptibly's virtual-child death model excludes the stop class: a stop signal never kills a real foreground child, so the delivery defers to the sleep's completion like any other trapped arrival. Regression pins: tests/issue2344_stop_signal_trap_regressions.rs (10 tests, watchdog-bounded so a regression fails instead of hanging: the child runs in its own process group and a watchdog SIGCONT/SIGKILL caps every run). Oracle-verified byte-for-byte against GNU bash 5.3.20 via script files, including the deferral shape (trap dispatches after the foreground wait completes, $? preserved), the wait-builtin interrupt (128+20), child non- inheritance of the handler, and the entry-ignored hard-ignore.
caomengxuan666
marked this pull request as ready for review
October 31, 2026 06:44
…l-traps # Conflicts: # src/builtins/kill.rs
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 #2344 — audit ch1 RC1 fix (RC-freeze audit-fix line).
Root cause
The kernel-signal backend's managed set (
MANAGED_CORE+ the hand-keptmanaged_trap_keystable insrc/builtins/kill.rs) is the eligibility set for the rule "the trap table drives kernel dispositions" — and it omitted exactly SIGTSTP/SIGTTIN/SIGTTOU/SIGCONT. The trap table recorded their traps (trap -p TSTPlisted them), but reconcile never computed a wish for them, so no handler was ever installed: trapped CONT silently discarded; trapped TSTP/TTIN/TTOU left at SIG_DFL → the shell really stopped (audit /procState: Tevidence) and the trap was dropped on resume;trap '' TSTPnever installed SIG_IGN.GNU:
trap.c:838 set_signal()installstrap_handlerfor ANY trapped signal, stop class included; delivery defers viapending_traps[]totrap.c:328 run_pending_traps()at a safe point, so the shell never stops.Fix (mechanism, not a case list)
MANAGED_CORE+managed_trap_keysgain TSTP/TTIN/TTOU/CONT — reconcile, entry snapshot, fork-child restore, and boundary dispatch all follow generically.exit_reroutesexcludes the stop class + CONT: GNU's terminating set (sig.c:127 terminating_signals[]) names neither (default actions are stop/resume, not termination), so an armed EXIT trap must not reroute an untrapped stop.sleep_interruptibly's virtual-child death model excludes the stop class: a stop signal never kills a real foreground child, so the delivery defers to the sleep's completion.Verification
$?preserved),waitinterrupted at 148, untrapped TSTP still stopping with an EXIT trap armed and aftertrap -, child shells inheriting SIG_DFL (child stops, parent trap silent), and entry-ignored TSTP staying un-trappable.tests/issue2344_stop_signal_trap_regressions.rs: 10/10 locally via the build slot (12.76s). Pins are watchdog-bounded (own process group, grace SIGCONT, hard SIGKILL) so a regression fails instead of hanging CI.signal_trap_coverage_regressions7/7,issue1034_sleep_trap_deferral_regressions2/2,builtins::killlib tests 22/22.cargo checkclean; fmt applied to touched files only; 0 CR.Gate split: full suites = CI + collector. Not verified here: interactive/tty faces (terminal-generated ^Z during a builtin sleep, TTOU write-triggered delivery) — same gap the audit recorded for RC1.