Repository navigation
fix7/sig-trap: kill multispec, async trap table, subshell self-kill routing, SIGINT sleep/discard (#1630 #1631 #1639 #1640 #1654) - #1784
Merged
Conversation
…are pid operands
GNU builtins/kill.def (kill_builtin option loop): the bare -SIG branch
is gated on saw_signal == 0 — 'We only process the first one seen;
other arguments may signify process groups (e.g., -num == process
group num)'. A later -SIG word is an operand: numeric (negative
included) takes a kill_pid attempt with a '({pid}) - {strerror}'
failure diagnostic, non-numeric takes the sh_badpid diagnostic, and
neither is silently absorbed.
- kill_request: track saw_signal (the -s/-n branches stay live after
a bare spec, per 'kill -TERM -s USR1 pid'), break the scan at a
second bare spec, strip exactly one leading dash. The tracked-job
path no longer retargets the delivery to the last spec seen.
- Tracked path: a signed numeric operand that is not a job is
delegated to the kill builtin and its verdict folded into
any_failed/any_succeeded (process-group delivery attempt, not a
badpid).
- builtins/kill.rs: negative pid operands now deliver via kill(2)
with the signed value (process-group addressing) and report
'kill: ({pid}) - {message}' on failure, instead of being silently
skipped.
Regression: tests/issue1631_kill_multispec_regressions.rs (4 tests,
oracle-verified against GNU bash 5.3.20).
Fixes the code side of rubash#1631.
…rap table In GNU a ( ) subshell is a separate process: 'kill -s TERM $$' inside it addresses the PARENT shell, whose own dispositions judge the delivery — the subshell's 'trap "" TERM' cannot shield the parent. In the flat one-process model the subshell body's trap reprograms the single kernel disposition, so the raw raise(2) was swallowed by the child's SIG_IGN (ignore form) or queued under the child's handler and dropped as stale after the parent boundary reconciled back (caught form): the parent survived a TERM it should have died from. Fix (deferral routing, the mirror of the #1461 fake-BASHPID intercept): - Executor::execute_kill arms a thread-local ancestor route while the executor is a flat subshell layer sharing the shell's process (same predicate the boundary dispatcher itself uses). - The kill builtin, route armed, queues own-pid deliveries of boundary-adjudicable signals (kill.rs ANCESTOR_SIGNALS) instead of raising them. SIGKILL/stop class keep raw raise semantics. - run_pending_signal_traps drains the ancestor queue first at the depth-0 boundary — no stale-handler check — and adjudicates with the restored top-level table through the unchanged dispatch body: trapped runs the parent action after the subshell completes, ignored drops, untrapped is the 128+sig death (EXIT trap included). Regression: tests/issue1654_subshell_trap_leak_regressions.rs (7 tests, exact stdout + exit status, matrix verified against GNU bash 5.3.20: ignore/catch/parent-trap/parent-ignore/nesting depth 2/ EXIT-trap-on-death/plain control).
…spawn children GNU trap.c reset_signal_handlers keeps inherited traps LISTED in a subshell with their dispositions reset; '( trap -p ) &' prints the parent's EXIT/USR1/ignored entries. The async respawn path stripped every __RUBASH_TRAP* key from the child env (to keep inherited traps from firing and to kill stale OS-env copies), which also dropped the listing: 'trap -p' inside '( ... ) &' and backgrounded builtins printed nothing and eval "$(trap -p ...)" could not restore. After the strip, clone the live table, apply the same reset_for_subshell_child transform the flat subshell path uses, and forward the resulting __RUBASH_TRAP* keys into the child env_map — reset-but-listed, identical to the in-process shape, inserted before the #1035 async-signal seeding so that behavior is unchanged. Regression: tests/issue1630_async_trap_table_regressions.rs (4 tests).
#1640 (follow-up of #1250): 'sleep 25; echo AFTER rc=$?' plus a SIGINT addressed to the shell's pid ONLY must let the sleep complete (GNU: the real child never receives it, completes, and the recorded interrupt is forgotten, rc=0). sleep_interruptibly consumed any pending SIGINT at two points without asking its origin. Both consumption points now require kernel_signals::last_delivery_kernel_caused(SIGINT) — the origin record drain() keeps from signal_hook's WithOrigin (SI_KERNEL = terminal-generated; a kill(2) from any process is not): ForegroundBuiltinSigintGuard::take_sigint_abort leaves a shell-only SIGINT queued for the boundary instead of aborting, and the observe_signals_while_blocked error fold in sleep_interruptibly swallows a non-kernel 130 and keeps sleeping. The trapped path already required the same origin (#1034) and is unchanged. Regression: the issue1640 test in tests/issue1639_1640_interactive_sigint_regressions.rs (script(1) PTY; committed with the #1639 change that introduces the file).
…s by SIGINT #1639 (follow-up of #1250): Ctrl-C during a foreground wait left $?=130 but the rest of the line still ran. GNU jobs.c (waitchld's job-control/foreground/WTERMSIG==SIGINT block) does ADDINTERRUPT there and the executing list throws to the top-level reader (throw_to_top_level): the whole line is discarded in every frame, $? stays 130, and the discard outranks || / && status evaluation. A trapped SIGINT does not discard (the trap runs, the list continues). - Waits only MARK Executor::fg_sigint_unwind (status already 130): the external path when the child exits by SIGINT under an armed ForegroundWaitSigintGuard, the builtin sleep fast path on an untrapped kernel-caused SIGINT abort. The guard now holds the recording mailbox handler (kill::hold_fg_sigint, as GNU's wait_sigint_handler records instead of dying) instead of SIG_IGN. - execute_ast_inner_body's loop head converts the mark into the new ExecuteError::SigintUnwind before the next command dispatches (closing an open flat subshell region first, with the handle_exit_code restore discipline); execute_ast flushes a mark left by a unit-final wait; run_source_impl records it as a plain 130 reader discard; the child-script boundary converts it to the child's 130 status. - foreground_sigint_needs_protection now keys on the reader-session predicate (interactive_reader_session) without the expansion discard's depth/comsub conditions: in the flat model a frame's foreground wait IS the process's foreground wait. Regression: tests/issue1639_1640_interactive_sigint_regressions.rs (7 script(1)-PTY tests: builtin/external/function-frame/subshell- frame/||-list discards, trapped control, and the #1640 pid-directed case; all shapes probed against GNU bash 5.3.20 first).
…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.
This was referenced Oct 26, 2026
Closed
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.
Summary
fix7/sig-trap slice: five signal/trap fixes, each with GNU bash 5.3.20 oracle-pinned regression tests (one issue per commit).
[bug] kill with multiple signal specs silently overrides instead of treating later -SIG as a pid operand #1631
kill: only the first bare-SIGspec is an option; later-SIGwords are pid operands (GNUkill.defsaw_signal rule).kill_requestno longer silently overwrites the signal; negative operands go through real process-group delivery with({pid}) - ...diagnostics instead of a silent skip.[bug] trap-ignore in subshell leaks SIG_IGN to parent: parent survives TERM it should die from #1654 subshell-layer self-kills (
kill … $$inside a flat( )layer) are judged by the top-level layer's trap table: deliveries are routed to an ancestor queue and adjudicated at the boundary after the parent table is restored, instead of being swallowed by the layer's kernel disposition (SIG_IGN leak / stale handler note).[bug] Async subshells and async builtins lose the inherited trap table (trap -p prints nothing) #1630 async respawn children receive the inherited trap table in reset form (
__RUBASH_TRAP*forwarded through the samereset_for_subshell_childtransform as the flat path), sotrap -pin( … ) &/ async builtins lists inherited traps again.[bug] shell-directed SIGINT aborts builtin sleep with 130; GNU lets it complete (rc=0) #1640 builtin
sleep: only a kernel-caused SIGINT (terminal ^C,si_codeSI_KERNEL) aborts the virtual child; a shell-directedkill -INT <shell pid>lets the sleep complete with rc=0, as GNU's real foreground child survives it.[bug] Ctrl-C during fg wait runs the rest of the line; GNU discards it (fresh prompt) #1639 a foreground wait (builtin sleep virtual child or external child) dying by untrapped SIGINT in an interactive reader session discards the rest of the line: wait sites mark
fg_sigint_unwind, the list loop converts it toExecuteError::SigintUnwindbefore the next command,$?stays 130 for the next command,||fallbacks do not run, and the unwind crosses function/subshell frames (GNU jobs.c waitchld ADDINTERRUPT → throw_to_top_level).[bug] Ctrl-C during fg wait runs the rest of the line; GNU discards it (fresh prompt) #1639 follow-up (ported from fix: Ctrl-C during fg wait discards rest of line (#1639) #1702, thanks @a-rookie-of-C-language): a Ctrl-C interrupting a blocking
readalso marksfg_sigint_unwind(at the three points where read returns an interrupted status), and loop/eval frame abandonment is pinned by tests — shapes the original slice lacked, verified against GNU 5.3.20 under the same PTY carrier.Fixes #1630
Fixes #1631
Fixes #1639
Fixes #1640
Fixes #1654
Verification
issue1630_async_trap_table_regressions(4),issue1631_kill_multispec_regressions(4),issue1639_1640_interactive_sigint_regressions(7, script(1) PTY carrier),issue1654_subshell_trap_leak_regressions(7), plusissue1035_1036_signal_table_regressions— all pass.--skip login_posix_env): only the known baseline failureownership_unary_operators_check_existing_file(same set as master baseline).Known residuals (documented in cluster report)
wait_with_outputfd-copy capture waits and pipeline-level waits have no SIGINT guard yet (redirected foreground external waits are not producers).