Repository navigation
fix: Ctrl-C during fg wait discards rest of line (#1639) - #1702
arookieofc wants to merge 1 commit into
Conversation
GNU (jobs.c:3305-3361) sets interrupt_state when a job-control foreground job is killed by SIGINT with SIGINT untrapped, so the loop or list breaks and the reader discards the rest of the line, leaving 128+SIGINT for the next command. Rubash ran the rest with rc=130 instead, on both the builtin-virtual-child and external wait paths. The fix rides the existing DISCARD abandon vehicle (ast_exec loop-top check) with a new sigint_discard_pending class marker that leaves 130 instead of the plain DISCARD 1. Trigger sites (all via arm_sigint_discard, gated on interactive AND untrapped): the four external-wait status sites, the two untrapped returns of sleep_interruptibly, and the two read sites that actually return 128+SIGINT. The gates match GNU's probed boundaries: scripts continue after a child SIGINT death (bash 5.2 probe), a trapped SIGINT runs its action and the list continues, and the discard dies with a flat ( ) region like GNU's forked subshell boundary. Inside an eval/source boundary list the discard abandons the whole unit (GNU's interrupt_state breaks the entire parse_and_execute loop), unlike evalerror DISCARD's per-line skip. Known adjacent items, not fixed here: pipeline fg waits (stage statuses need their own SIGINT scan); ^C inside a flat ( ) region kills the shell today (the fg SIGINT guard arms only at subshell_depth == 0 — a pre-existing flat-region signal gap); a trapped SIGINT inside a loop keeps the loop in rubash while GNU job-control breaks it; the flag rides the sleep/read aborts, so #1640's kernel-caused gate (its own branch) decides when a shell-directed kill(2) INT arms it at all. Tests: new tests/issue1639_ctrlc_discard_rest.rs (script(1) PTY harness, transcript assertions only): builtin, external, ||, loop, trapped-continues, read, single-line eval, multi-line eval, plus a script-mode child-SIGINT-continues negative — 9/9.
…rrupts read (#1639) A Ctrl-C interrupting a blocking read is an untrapped-SIGINT foreground wait: GNU returns 128+SIGINT from the builtin and the executing list throws to the top level (jobs.c waitchld ADDINTERRUPT model), discarding the rest of the line. The read interrupt flag is only ever set under the armed builtin guard (interactive + untrapped), so mark fg_sigint_unwind at the three points where an interrupted status is actually returned; the list loop converts it to SigintUnwind like the sleep/external producers. Read shape and test set ported from PR #1702 by a-rookie-of-C-language (whose evalerror-vehicle implementation covered read/loop/eval shapes this slice lacked); loop and eval frame tests added on the same PTY carrier — the SigintUnwind error already crosses those frames.
|
Thank you for this — it covered shapes the parallel sig-trap slice (#1784, now merged) did not, and those parts were ported into the slice with credit rather than merging a competing implementation of the same issue. What #1784 already covered (independently, via a different vehicle — a What your PR had that the slice lacked — verified against GNU 5.3.20 under the same PTY carrier and ported into #1784 (commit a2500d6, credited to this PR in the commit message):
One divergence worth noting: your header describes the discard as subshell-bounded (parent list continues), but the GNU 5.3.20 probe for Closing as incorporated/superseded by #1784. The duplication came from the slice branch not being pushed while in flight — on us, not on you. |
Fixes #1639.
Bug
Ctrl-C during a foreground wait ran the rest of the line (
sleep 25; echo AFTERprintedAFTER rc=130); GNU discards it (fresh prompt,$?= 130 for the NEXT command). Both the builtin-virtual-child and external wait paths diverged the same way.GNU rule (probed + sourced)
third_party/bash/jobs.c:3305-3361: a job-control foreground job killed by SIGINT with SIGINT untrapped setsinterrupt_state, so the loop or list breaks. Probes against bash 5.2 pinned the boundaries:;tail,||fallback, whole loop body + following commands).-i): a child SIGINT death is just status 130, execution continues.readinterrupted by ^C: rest of line discarded, next command sees 130.Rubash has no job control; its interactive fg wait is the job-control-like mode (jobs.c
wait_formodel, rubash#1250), so the discard applies to interactive waits.Changes
sigint_discard_pendingclass marker riding the existing DISCARD abandon vehicle (ast_exec loop-top check), leaving 130 instead of the plain DISCARD 1. It is cleared at every pending-clearing boundary like the other class markers.arm_sigint_discard(external_inner.rs), gated on interactive AND untrapped, called from: the four external-wait status sites, the two untrapped returns ofsleep_interruptibly, and the two read sites that actually return 128+SIGINT (the invalid-name/error arms return 1 and do not arm).interrupt_statebreaks the entireparse_and_executeloop), unlike evalerror DISCARD's per-line skip (rubash#637). At the top-level reader a following queued line still runs as a new command.Verification
New
tests/issue1639_ctrlc_discard_rest.rs(script(1)PTY harness, transcript assertions only —scriptitself sits in the PTY foreground group, so its exit code is contaminated after ^C): builtin, external (/usr/bin/sleep),||, loop, trapped-continues, read, single-line eval, multi-line eval, plus a script-mode child-SIGINT-continues negative — 9/9.Regression: DISCARD family (1226, 1318, 1541, 1469, 1603), eval family (637, 1563, 1013, 282), coproc/jobs family, signal/trap family, read family — all green.
issue1035_1036::background_compound_body_can_still_trap_intfails identically on pure master (verified via stash during #1640) — pre-existing, unrelated.Known adjacent items, not fixed here
( )region kills the shell today (the fg SIGINT guard arms only atsubshell_depth == 0) — a pre-existing flat-region signal gap, separate issue. The boundary branch in the abandon check mirrors the evalerror subshell branch for when that gap closes.