Repository navigation
WIP: interactive Ctrl+C survival — GNU signal dispositions + DISCARD unwind (#1662) - #1809
Conversation
…ns + DISCARD unwind) (#1662) GNU spec: sig.c:231 initialize_terminating_signals(), called from sig.c:316 initialize_shell_signals() only `if (interactive)`; the same block installs SIGINT -> sigint_sighandler and SIGTERM -> SIG_IGN for interactive shells, independent of the trap table. An interactive SIGINT abort ends the current command with 128+SIGINT and the reader prompts again (DISCARD-class unwind) — it is not a shell exit. rubash had two stacked gaps: 1. Dispositions were derived purely from the trap table (reconcile_kernel_trap_dispositions): an untrapped interactive SIGINT sat at SIG_DFL everywhere outside the #1414 foreground-guard windows, so the kernel default action killed the shell on the first ^C at the prompt or during in-process builtin execution (PTY-verified on master: death by signal 2 for a single C-c at an idle prompt and during `while :; do :; done`; pipelines died too; only the external-command wait survived, via the guard). #1250's root was never fully closed for interactive use; the 1.4.4 release line additionally lacks the #1414 guards entirely. 2. With a handler installed, the boundary dispatch aborts the unit with Err(ExitCode(128+sig)), and run_source_impl recorded every top-level ExitCode as an exit jump — so the interactive driver ended the session anyway and the process exited 130 voluntarily. The unwind lacked the DISCARD classification the parse-error path already has. Fix (engine-side, no host change): - kill.rs reconcile: when __RUBASH_INTERACTIVE=1, an untrapped, non-reset SIGINT wishes the mailbox Handler and SIGTERM wishes Ignore (both skip entry-ignored signals; an armed EXIT trap's Handler reroute still wins for TERM; user traps unaffected). The steady-state fast path no longer skips interactive shells, so the pin applies from the first reconcile. - script_driver.rs run_interactive_stdin: one reconcile at driver entry so the dispositions exist before the first prompt is read. - Executor gains signal_discard_pending: the boundary dispatch sets it for an untrapped-signal abort in an interactive shell, and run_source_impl's ExitCode arm consumes it instead of recording an exit jump. Non-interactive shells keep the exit classification (a script shell still dies at 128+sig, running any EXIT trap). - tests/issue1662_interactive_sigint_survival.rs: prompt / builtin loop / burst survival with rc=130, plus the sig.c:315-316 other half — a non-interactive shell still dies by the SIGINT default action itself (signal 2), pinning that the fix does not widen. Verification: PTY survival matrix (niu -i + bare rubash, single and x5-burst C-c across ext/loop/pipe/prompt/half-typed, GNU 5.3.20 control) green x2 runs on the fixed build; lib failure set identical to master baseline (771 pass, only ownership_unary_operators_check_existing_file); diffcorpus 306 subset of {ms10}. Refs #1662 (closure waits for the reporter's retest on a shipped release; the release line 1.4.4 contains neither this fix nor #1414).
…mantic change) # Conflicts: # src/builtins/kill.rs
Integration onto current master (main-session integration pass, 2026-10-27)This branch has been integrated onto master
Conflict resolution (1 conflict)
Resolution keeps both accessors verbatim; neither side's code was dropped or altered. All other files of this PR ( Gates on the merged tree (single build slot, JOBS=1, debuginfo=0, purified env; logs via python file handles with
|
…ler pin (unixwin#1824) Regression introduced by PR unixwin#1809 (commit 5c3abde, merged as 5275dde): pinning an interactive shell's untrapped SIGINT to the mailbox handler at every command boundary (GNU sig.c:315-316 initialize_terminating_signals — an interactive shell catches SIGINT itself from startup) invalidated the foreground guards' arming predicate, which read "a handler is installed" as "the trap path owns the delivery". With untrapped SIGINT sitting at the handler from the boundary on, the guards never armed during in-process blocking waits, so the delivery queued in the mailbox with no consumer: inside a subshell frame the builtin sleep slept through the ^C (observe_signals_while_blocked is frame-guarded, and take_sigint_abort is armed-gated), and a blocked `read` ate the next input line as its own input while the stranded delivery discarded the rest of the unit at the next boundary. Bisect over the four-merge interval: both unixwin#1639 pins green at a9385b4 (unixwin#1813) and 44ee0ae (unixwin#1815), red at 5275dde (unixwin#1809); pin texts byte-identical across the whole interval, pins unedited. Fix the invariant at the shared predicate (foreground_sigint_needs_protection): protection is needed when SIGINT is UNTRAPPED — the trap table decides ownership — and the kernel disposition is one of the two untrapped steady states, SIG_DFL or our mailbox handler. A trapped SIGINT keeps the trap path (the guard must not steal its delivery); an entry-ignored SIGINT stays at SIG_IGN and untouched. The hold/release pair becomes symmetric: hold_fg_sigint records the steady state it found (first holder wins) and release_fg_sigint restores it, so a wait that began under the pin leaves SIGINT at the Handler instead of flipping it to Default until the next boundary reconcile re-pins it. GNU references: sig.c:315-316 (interactive SIGINT catch), jobs.c:3086-3102 (wait_for records deliveries during a wait), jobs.c:3315-3316 (ADDINTERRUPT discard classification).
Refs #1662
What
Interactive shells now hold GNU's startup signal dispositions
(sig.c:316
initialize_shell_signals, interactive-only): untrappedSIGINT is caught by the engine's mailbox instead of sitting at
SIG_DFL, untrapped SIGTERM is ignored, and the resulting abort is
classified DISCARD (prompt again, $? = 130) instead of an exit jump.
One reconcile at interactive-driver entry covers the first prompt.
Why
On master, a single Ctrl+C at an idle prompt, during a builtin loop,
or during a pipeline kills the shell process outright (PTY-verified:
death by signal 2; niu on master dies the same way in the loop/pipe
cells). Only the external-command wait window was covered, by the
#1414 guards. Full per-cell matrix + root-cause write-up in the
cluster report (linked from the #1662 follow-up comment).
Scope / non-goals
and unwind-class-level only).