Repository navigation
WIP: fix(android-signal): kill %1 TERM disposition leak + fg SIGINT forwarding (#1990, #1991) - #1996
Merged
Merged
Conversation
… live state word (rubash#1991) pre_exec_child_dispositions (the trap.c:1489 restore_original_signals port) decided the SIG_IGN branch from the live kernel state word, which also carries shell-policy ignores: an interactive shell ignores SIGTERM for itself (sig.c:338-339, after get_original_signal snapshots the entry disposition), and every spawned child therefore inherited SIGTERM=SIG_IGN. kill %1 then returned 0 into a disposition that discards the signal -- the job ran on, immune to TERM (kill -9 still worked, matching the report's PID-form observation). The ignore decision now reads the entry snapshot plus a new TRAP_IGNORED record that the boundary reconcile maintains from the trap table itself (trap '' only), exactly GNU's two sources. The trap '' shield is preserved (verified: a trap '' TERM job still ignores kill %1 and dies to kill -9 %1). Also in kill.rs: a monotonic SIGINT_KERNEL_EPOCH counter drained from SI_KERNEL deliveries (groundwork for the rubash#1990 foreground-wait forwarding in the next commit; the last-wins KERNEL_CAUSED bit cannot express 'arrived during this wait'). script_driver: the library interactive entry (run_interactive_stdin) never established job control -- that step lived only in the binary's startup (main.rs apply_startup_job_control), so library-host interactive sessions (niu's engine REPL) ran with monitor permanently off and fg/bg refused 'no job control' on a real terminal. GNU establishes job control for every interactive shell in initialize_shell_basics (jobs.c:4869). The entry now defaults monitor on for interactive sessions, once per process, respecting an explicit __RUBASH_SETOPT_monitor transport value.
…hild (rubash#1990) wait_external_child's unix arm blocked in child.wait() and trusted the kernel's process-group delivery to kill the foreground command. rubash children share the shell's process group (no setpgid), so on a healthy terminal that delivery lands -- but when the spawn arrangement leaves the child outside the terminal's foreground group (the Termux/Android PTY sessions behind this issue, or a child that re-sessions itself), the delivery reaches only the shell: the wait then sat until the child's natural end and the recorded interrupt was forgotten ($?=0), while in-process waits settled 130 over a command that never died. GNU never faces this: its children lead their own groups (jobs.c make_child) and wait_for (jobs.c:3064) only records. The armed wait (interactive session, SIGINT untrapped -- the ForegroundWaitSigintGuard case) now polls try_wait in 10ms slices, drains arrivals with the builtin guard's take/inspect/requeue pattern, and when the kernel-SIGINT epoch (kill.rs) moves past the snapshot taken at wait start, forwards SIGINT to the child exactly once: group form when the child made itself a group leader (the delivery it missed), directed form otherwise (the group form would hit the shell's own group). The forwarded arrival is consumed by the wait, not left queued to be re-adjudicated against the next input line. A child that catches or blocks SIGINT is left alone after the one forward and the wait settles with the child's own status -- the child_caught_sigint outcome (jobs.c waitchld cleanup). Unarmed waits keep the plain blocking waitpid; directed kill(2) SIGINT is not forwarded (GNU's real child would not have died from it either). Regression pins (tests/issue1990_1991_signal_job_regressions.rs): the #1990 PTY pair (setsid-resessioned child + healthy child) and the #1991 kill %1 TERM/STOP delivery, honest nonzero for an unknown jobspec, and the trap '' shield.
caomengxuan666
marked this pull request as ready for review
October 28, 2026 16:51
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Android real-device acceptance fixes (vivo Android 15 / Termux, GNU bash on the same device as oracle).
Fixes #1990
Fixes #1991
#1991(a) —
kill %1returned 0 but never deliveredThe delivery chain was intact end to end (
execute_kill→ jobspec resolution →libc::kill(pid, sig)runs and returns 0). The job process itself was born ignoring SIGTERM:/proc/<jobpid>/statusSigIgn = {TERM, XFSZ} on master, reproducible on desktop Linux PTY.Root cause, mechanism layer:
kernel_signals::pre_exec_child_dispositions(the trap.c:1489restore_original_signalsport) read the live kernel state word for its ignore branch. That word also carries shell-policy ignores — an interactive shell ignores SIGTERM for itself (sig.c:338-339, installed afterget_original_signalsnapshots the entry disposition) — so every child of an interactive shell inheritedSIGTERM=SIG_IGN. GNU restores children from the entry snapshot plus thetrap ''set only.Fix: the ignore branch now consults the entry snapshot plus a new
TRAP_IGNOREDrecord maintained by the boundary reconcile from the trap table itself. Thetrap ''shield is preserved (atrap '' TERMjob still ignoreskill %1, dies tokill -9 %1). Unknown jobspecs already errored honestly (rc=1); the fake part was only the 0 for existing jobs.#1991(c) —
fg/bg"no job control"The gate itself is GNU-faithful (monitor option only, fg_bg.def:108-113) and the standalone binary establishes monitor correctly (local PTY:
$-=himBHs,fg %1attaches). The engine-side gap: job-control establishment lived only in the binary's startup (main.rs apply_startup_job_control); the library interactive entryscript_driver::run_interactive_stdin— how hosts (niu) drive interactive sessions — never established it, so host-driven interactive sessions had monitor permanently off. The entry now defaults monitor on for interactive sessions (once per process; an explicit__RUBASH_SETOPT_monitortransport value is respected). GNU establishes job control for every interactive shell in initialize_shell_basics (jobs.c:4869), whoever drives it.#1990 — foreground wait never forwards SIGINT
The unix foreground wait blocked in
child.wait()and trusted the terminal's process-group delivery to kill the child. rubash children share the shell's process group (no setpgid); when the spawn arrangement leaves the child outside the terminal's foreground group (the device PTY arrangement; a child that re-sessions itself), the delivery reaches only the shell — the wait sat until the child's natural end and forgot the interrupt ($?=0), the report's second timing shape. GNU's children lead their own groups, sowait_for(jobs.c:3064) never needs to forward.Fix: the armed wait (interactive, untrapped SIGINT) polls
try_waitin 10 ms slices; when the new monotonic kernel-SIGINT epoch (drained from SI_KERNEL deliveries) moves past the wait-start snapshot, it forwards SIGINT to the child once — group form if the child made itself a group leader, directed otherwise. The forwarded arrival is consumed by the wait (not re-adjudicated against the next input line). A child that catches/blocks SIGINT settles with its own status (thechild_caught_sigintoutcome). Unarmed waits keep the plain blocking waitpid; directed kill(2) SIGINT is not forwarded.Verified on Linux PTY:
setsid /usr/bin/sleep 30+ ^C → prompt back in 0.17 s, child gone (pgrep before/after), $?=130, session alive; healthy virtual/external forms unchanged.Regression pins
tests/issue1990_1991_signal_job_regressions.rs(unix): kill %1 TERM/STOP delivery proven viawait %1= 143/137, unknown jobspec rc=1,trap ''shield preserved, PTY ^C against a re-sessioned child (20 s deadline vs the child's 30 s natural life) and a healthy child.Real-device re-verification (both #1990 timing shapes, the surviving pid's /proc cmdline for shape one,
echo $-for the fg/bg face) goes back to the Android agent.