Repository navigation
WIP: fix trapped SIGINT discarding the line after builtin sleep (#1811) - #1821
Conversation
… sleep (#1811) GNU spec: jobs.c:3315-3316 waitchld (foreground job killed by SIGINT) queues ADDINTERRUPT only when signal_is_trapped(SIGINT) == 0. A trapped delivery is merely recorded (trap.c:553 trap_handler -> trap.c:545 set_trap_state, pending_traps[sig]++); its action runs at the next command boundary (execute_cmd.c:643 run_pending_traps) and the executing list then CONTINUES with the interrupted command's 128+SIGINT status. rubash divergence (PTY, interactive): trap 'echo TRAPPED_INT' INT; sleep 6; echo AFTER1639 rc=$? ^C -> TRAPPED_INT printed, then the rest of the line was discarded (next line saw $?=130); GNU prints AFTER1639 rc=130 and the next line sees $?=0. Root cause: the builtin-sleep fast path re-adjudicates the abort after sleep_interruptibly returns Some(SIGINT) (by then the trap has already run). Its untrapped test looked the trap table up with the bare name "INT". The table is keyed verbatim by trap_key() over the canonical names builtins::trap::normalize_signal returns — the SIG-prefixed SIGNALS entries for real signals ("SIGINT"); bare names exist only for the EXIT/ERR/DEBUG/RETURN pseudo-signals — and every other lookup site honors that form (signal_trap_name(), the "SIGCHLD" literal). The bare-"INT" lookup could therefore never hit a stored trap: every trapped abort of the virtual child read as untrapped, fg_sigint_unwind was marked, and the list boundary converted it to SigintUnwind, discarding the rest of the line. Fix: look up the canonical "SIGINT" key, restoring the invariant that this adjudication consults the same trap table every sibling site consults. No new predicate, no behavior change for the untrapped case (lookup still misses, discard still marked), the ignored case (trap '' stores Some("") under the canonical key, so no discard — GNU counts an ignored SIGINT as trapped for ADDINTERRUPT), or the #1809 DISCARD semantics for untrapped waits. Regression seed: tests/issue1639_1640_interactive_sigint_regressions ::issue1639_trapped_int_runs_trap_and_continues_line (unchanged). Fixes #1811
|
Verification evidence (cluster issue1811, all runs via the single build slot, python file-handle logs + .done markers; full logs in the cluster REPORT): Fix: commit cbfc4c1 — one lookup in the builtin-sleep arm of Seed: Six sig files: fixed tree 32 passed / 2 failed. Baseline control on pristine 5275dde (same two affected files): the seed plus the same two failures — i.e. the fix flips exactly the seed and introduces no new failure. The two remaining reds are pre-existing on this master and outside #1811's surface (untrapped discard in subshell/read frames; transcripts byte-identical in shape on both trees):
issue1662 targeted: 4 passed / 0 failed (#1809 semantics intact). One adjacent residual documented in the cluster REPORT (not fixed here, different mechanism): untrapped ^C during the |
Fixes #1811
Divergence (sig-trap GATE-READJUDICATION §C, the one real product divergence of the 11)
Interactive PTY:
trap 'echo TRAPPED_INT' INT; sleep 6; echo AFTER1639 rc=$?, ^C during the sleep.AFTER1639 rc=130prints, next line sees $?=0.TRAPPED_INTprinted) but the rest of the line was discarded via the untrapped path (next line saw $?=130).Root cause
The builtin-sleep fast path re-adjudicates the abort after
sleep_interruptiblyreturnsSome(SIGINT)(the trap has already run by then). Its untrapped test looked the trap table up with the bare name"INT". The table is keyed verbatim bytrap_key()over the canonical namesnormalize_signalreturns — SIG-prefixed SIGNALS entries for real signals ("SIGINT"); bare names exist only for the EXIT/ERR/DEBUG/RETURN pseudo-signals — and every other lookup site honors that form (signal_trap_name(), the"SIGCHLD"literal). The bare-"INT"lookup could never hit a stored trap, so every trapped abort read as untrapped,fg_sigint_unwindwas marked, and the list boundary converted it toSigintUnwind.GNU: jobs.c:3315-3316 waitchld queues ADDINTERRUPT only when
signal_is_trapped(SIGINT) == 0; a trapped delivery is only recorded (trap.c:553 trap_handler -> trap.c:545 set_trap_state) and its action runs at the next boundary (execute_cmd.c:643 run_pending_traps), after which the list continues with the wait's 130.Fix
One lookup in
src/executor/command_dispatch_primary.rsnow uses the canonical"SIGINT"key (with the invariant spelled out in the comment). No new predicate; untrapped case unchanged (lookup still misses, discard still marked); ignored case (trap '' INTstoresSome("")under the canonical key) now also continues, as GNU counts it as trapped for ADDINTERRUPT; #1809 DISCARD semantics and the G-01 lock narrowing untouched;src/lexer/continuation.rsuntouched.Regression seed:
issue1639_trapped_int_runs_trap_and_continues_line— unchanged, expected to turn green with this fix (verification numbers land in the cluster REPORT and a follow-up comment; PR stays draft, no self-merge).