Skip to content

WIP: interactive Ctrl+C survival — GNU signal dispositions + DISCARD unwind (#1662) - #1809

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/1662-interactive-sigint-survival
Oct 27, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/1662-interactive-sigint-survival

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1662

What

Interactive shells now hold GNU's startup signal dispositions
(sig.c:316 initialize_shell_signals, interactive-only): untrapped
SIGINT 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

…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
@caomengxuan666

Copy link
Copy Markdown
Member Author

Integration onto current master (main-session integration pass, 2026-10-27)

This branch has been integrated onto master a9385b4c (which now includes #1810 nvm-alias and #1813 sig-trap pin fixes) with a plain merge — no rebase, no history rewrite, no force push.

Conflict resolution (1 conflict)

src/builtins/kill.rs — the only conflicted file. Both sides had inserted a new accessor in mod kernel_signals at the same spot after handler_installed():

Resolution keeps both accessors verbatim; neither side's code was dropped or altered. All other files of this PR (trap_exec.rs signal_discard_pending, script_driver.rs DISCARD + prompt-wait dispatch, mod.rs, init.rs, public_accessors.rs, command_substitution.rs, the new test file) auto-merged, and the merged kill.rs retains master's #1654 adjudication path untouched. src/lexer/continuation.rs is not touched by this merge.

Gates on the merged tree (single build slot, JOBS=1, debuginfo=0, purified env; logs via python file handles with .done markers)

  • cargo build --locked: rc=0
  • issue1662 targeted pins: 4 passed / 0 failed
  • lib (--skip login_posix_env): 771 passed / 1 failed / 1 ignored — the single failure is ownership_unary_operators_check_existing_file, identical to the master baseline set
  • PTY matrix (this line's tmux harness, bare-rubash cells on the merged-tree binary): rubash 10/10 survived, INTRC=130 in every cell, half-typed line DISCARDED — cell-for-cell identical to the GNU bash 5.3.20 control (10/10)
  • diffcorpus 306: 306 PASS / 0 FAIL (ms10 also passed this run; effective failure set ∅ ⊆ {ms10})
  • rustfmt: the 7 individually-checked changed files are clean; src/executor/mod.rs's module tree shows the same 6 pre-existing drift files on master and on the merged tree (zero new drift); CR=0 on all changed files

Full log + report: cluster rubash-fix9/clusters/ctrlc-1809-integ/ (gates.log, results-integ1.txt, REPORT-INTEG.md).

@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 03:56
@caomengxuan666
caomengxuan666 merged commit 5275dde into master Oct 27, 2026
8 of 9 checks passed
SpookyWaste pushed a commit to SpookyWaste/rubash that referenced this pull request Oct 29, 2026
…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).
@caomengxuan666
caomengxuan666 deleted the fix/1662-interactive-sigint-survival branch October 30, 2026 01:41
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