Skip to content

fix(executor): classify a wait-time shell-only SIGINT by the child's outcome (Refs #2729) - #3695

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2729-shell-sigint-child-outcome
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2729-shell-sigint-child-outcome

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-FIX】

Problem

A kill(2) SIGINT delivered to a non-interactive script shell while it waits on a foreground child killed the shell mid-wait as a real signal death — whatever the child did. Pin issue2729_shell_only_sigint_wait: cells A (child exits normally → shell must survive, AFTER rc=0) and B (child dies by SIGTERM → shell survives, AFTER rc=143 + Terminated notice) were red; the group-SIGINT control (shell dies by SIGINT) was already green.

Root cause

GNU wait_for installs wait_sigint_handler for every non-job-controlled foreground wait (jobs.c:3088-3102) — it only records wait_sigint_received. waitchld then classifies by the job's outcome (jobs.c:4157-4163 child_caught_sigint), and the 4410ff cleanup re-raises / runs the trap only when the job itself died by SIGINT. Rubash's unarmed wait drained the mailbox through the plain observe_signals_while_blocked path — an untrapped SIGINT adjudicated to a 128+SIGINT death regardless of the child's end (or died by the kernel disposition outright).

Fix

  • ForegroundWaitSigintGuard::hold_for_script_wait: non-interactive arm of the same hold — untrapped SIG_DFL swaps to the mailbox handler for the wait's span; trapped SIGINT is already mailbox-routed (record-only, no hold); SIG_IGN stays unarmed (GNU restores it, jobs.c:3100-3101). held tracks who installed the routing so Drop releases only real holds.
  • observe_signals_while_blocked_recording_sigint: observe variant swallowing every queued SIGINT (trapped or not) into wait_sigint_received — GNU's handler records, never dispatches mid-wait.
  • wait_fg_child_recording: the record-only drain + tail drain before return (the handler stays installed until the wait ends).
  • wait_external_child tail classification: recorded SIGINT acts only when the child died by SIGINT — untrapped → termsig_death_pending (EXIT trap then die_by_signal, GNU termsig_handler/kill_shell); trapped → re-queued for the boundary. Otherwise discarded.

Legs

  • Pin issue2729_shell_only_sigint_wait: 2 red → 3/3 green
  • GNU 5.3.20 script-file probes byte-identical: child-normal (AFTER rc=0, exit 0) and child-SIGTERM (Terminated notice + AFTER rc=143, exit 0)
  • Signal-family pins green: 2730, 2735, 2695, 1825, 2346, 2353, 3284, 2236, 2241
  • issue698 unix_faces 2 reds reproduce on pristine master (pre-existing, unrelated)
  • RUSTFLAGS="-D warnings" cargo build --locked clean; cargo fmt --check clean on touched files

…outcome (Refs #2729)

GNU wait_for installs wait_sigint_handler for every non-job-controlled
foreground wait (jobs.c:3088-3102): the handler only records
(wait_sigint_received), and waitchld classifies by the job's outcome —
jobs.c:4157-4158 sets child_caught_sigint when the job exited normally
or died by another signal, jobs.c:4162-4163 clears it only when the
job died by SIGINT. The 4410ff cleanup acts on the recorded delivery
(trap / termsig_handler re-raise) only when child_caught_sigint == 0.

The wait drained the mailbox through the plain observe path, so an
untrapped shell-only SIGINT adjudicated as a 128+SIGINT death whatever
the child did. Add the recording arm: the guard's script mode swaps an
untrapped SIG_DFL to the mailbox handler for the wait's span (a
trapped SIGINT is already mailbox-routed; an ignored one stays
ignored, jobs.c:3100-3101), the recording wait swallows queued SIGINTs
into wait_sigint_received through observe's new sink, and the tail
re-raises via termsig_death_pending only when the child died by
SIGINT — trapped, the pending trap is re-queued for the boundary.
@caomengxuan666
caomengxuan666 merged commit aa25f16 into master Nov 15, 2026
8 of 11 checks passed
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