Repository navigation
WIP: fix(trap): trap reset disposition paths — reinstall after flip (#2348) + SIGINT REVERT special case (#2347) - #2349
Merged
Conversation
…n flip Refs #2348 GNU's REVERT and SET paths round-trip: trap.c:1398 reset_signal restores the original handler on `trap - SIG`, and trap.c:838 set_signal installs trap_handler again when a new trap is set, so a re-set handler receives deliveries. rubash wrote the trap table but left the flipped OS disposition in place — after `trap - USR1` a re-set USR1 trap never fired and the shell died by the signal; with a `trap ''` flip in between it stayed deaf at SIG_IGN instead. Root cause: the per-signal state machine desynced across its two records. signal-hook's Handle caches each signal's registration, so a later add_signal for the same signal is a no-op, while reconcile's Default/Ignore transitions overwrite the OS disposition with raw sigaction calls (SIG_DFL / SIG_IGN). After any flip away from the backend dispatcher, the slot stayed registered but the kernel no longer routed deliveries to it, and HANDLER_SET bookkeeping claimed the re-arm had happened. Fix: kernel_signals::ensure_handler now guarantees the recorded Handler state against the kernel — it captures the backend dispatcher verbatim at the first live install, and on a Handler wish whose OS disposition reads SIG_DFL/SIG_IGN it reinstalls that dispatcher, reconnecting the still-registered slot (including its chained previous disposition). The existing SA_RESTART normalization re-runs on the reinstalled action. Pins: tests/issue2348_2347_trap_reset_regressions.rs, issue2348_* shapes (direct/eval/source restores, TERM/HUP/SIG-spelling, the ignore-flip variant, and the clean boundaries: overwrite without clear, clear -> ignore, clear -> different signal, clear -> EXIT). The issue2347_* pins ride in the next commit with their fix.
… default Refs #2347 GNU trap_builtin's REVERT branch (builtins/trap.def:228-251) is a deliberate special case citing POSIX interp 751: after restore_default_signal (trap.c) early-returns on a hard-ignored signal, the builtin still installs termsig_sighandler for SIGINT in a non-interactive shell, so `trap - SIGINT` restores the fatal disposition even when SIGINT was ignored on entry. rubash no-oped the whole operation — the shell survived a self-sent SIGINT that kills GNU. The fix keys on SIGINT alone (SIGQUIT is the opposite hard-code — forced SIG_IGN, already matched — and TERM/USR1 reverts on entry-ignored signals stay no-ops in both shells): - trap.rs: the REVERT branch calls the disposition half after remove_trap's (correct) table no-op when SIGINT is entry-ignored. - kill.rs: a SIGINT_REVERTED flag records the revert. The builtin applies SIG_DFL synchronously for a non-interactive shell; an interactive shell records the flag and lets its SIGINT pin route the signal (GNU's sigint_sighandler seat). - reconcile: SIGINT's Default base resolves to SIG_DFL once reverted, and a first match arm in reconcile_kernel_trap_dispositions keeps the seeded entry-ignore table entry (an "" action) from re-imposing Ignore at every command boundary — the step that otherwise undid the builtin's install one command later. The interactive pin arm likewise honors the flag. Trap-set on SIGINT stays a hard-ignore no-op, and the `trap -p` listing keeps showing the entry-ignore entry, both exactly as GNU behaves after the revert. Pins: issue2347_* in tests/issue2348_2347_trap_reset_regressions.rs (real kernel entry-ignore via an ignoring launcher that execs the shell; death forms asserted on the parent wait status), covering the kill cell, the trap-set no-op, the no-op resets for TERM/USR1/QUIT, the untouched entry ignore, and the ordinary SIGINT-reset control.
caomengxuan666
marked this pull request as ready for review
October 31, 2026 06:40
This was referenced Oct 31, 2026
This was referenced Oct 31, 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.
Audit-fix wave (1.5.0 RC freeze, audit-fix line). Two REVERT-path disposition bugs from the pre-release audit chapter 1:
trap - SIG, re-setting a handler on the same signal updated the trap table but never reinstalled the OS disposition (signal-hook registration cache vs raw sigaction flips in reconcile). Fixed in commit 1: ensure_handler detects the desync and reinstalls the captured backend dispatcher.trap - INTon an entry-ignored SIGINT must revert to the fatal handler (builtins/trap.def:228-251, POSIX interp 751). Fix lands as the second commit on this branch.Regression pins: tests/issue2348_2347_trap_reset_regressions.rs (CI-uncovered target; run locally via the build slot by the cluster). Collector: full lib/regression + CI are yours per the wave split.