Skip to content

fix7/sig-trap: kill multispec, async trap table, subshell self-kill routing, SIGINT sleep/discard (#1630 #1631 #1639 #1640 #1654) - #1784

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix7/slice-sig-trap
Oct 26, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix7/slice-sig-trap

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

fix7/sig-trap slice: five signal/trap fixes, each with GNU bash 5.3.20 oracle-pinned regression tests (one issue per commit).

Fixes #1630
Fixes #1631
Fixes #1639
Fixes #1640
Fixes #1654

Verification

  • Targeted: 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), plus issue1035_1036_signal_table_regressions — all pass.
  • lib full (--skip login_posix_env): only the known baseline failure ownership_unary_operators_check_existing_file (same set as master baseline).
  • diffcorpus (306 cases vs GNU 5.3.20 oracle): effective failure set {ms10} ⊆ allowed set.

Known residuals (documented in cluster report)

  • wait_with_output fd-copy capture waits and pipeline-level waits have no SIGINT guard yet (redirected foreground external waits are not producers).
  • Trapped SIGINT inside a loop does not break the loop (GNU jobs.c loop_level branch).
  • Environmental deliveries to the process while a subshell layer owns the kernel disposition remain subject to the single-process model.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment