Repository navigation
WIP: SIGHUP hangup settlement — ctty acquisition, termsig funnel, huponexit - #2254
Conversation
…msig funnel, huponexit (Refs #2233) A shell whose controlling terminal hangs up (pty master closed) never learned of it: no controlling terminal was ever acquired (tty_nr=0), so the kernel delivered no SIGHUP, and both readers folded the terminal's EIO into a graceful EOF exit — jobs were orphaned and huponexit had no behavior. - script_driver::acquire_controlling_terminal mirrors GNU general.c:651 check_dev_tty (from main, shell.c:410); called from run_main and at the interactive reader's entry. - reconcile_kernel_trap_dispositions pins untrapped interactive SIGHUP to the signal mailbox (mirrors the SIGINT pin; sig.c:128 terminating set, sig.c:315-316). - The mailbox drains share a hangup verdict (note_untrapped_ hangup): untrapped SIGHUP with termsig armed (interactive, or an EXIT trap armed in any shell) records a hangup-death mark and unwinds exit-class; finish_shell runs the funnel in termsig order — hangup_all_jobs (jobs.c:1783; interactive gate per sig.c:621-622), EXIT trap, then death BY SIGHUP (kill_shell, sig.c:649). - Interactive reader: a tty read error polls for a queued hangup (poll_untrapped_hangup, no trap dispatch) before folding like EOF. Script reader: a read error takes GNU's READERR arm (parse.y shell_getc, FATAL_READERROR): 'script file read error' diagnostic and exit 128, partial group discarded. - huponexit: an interactive login shell with the shopt hangs its jobs up on the normal exit path (shell.c:1017-1020), after the EXIT trap (exit.def order). Regression pins: tests/interactive/hangup_pty.rs + support/ pty_hangup_probe.py (18 legs across the script route, the -i interactive route, and login huponexit); driver calibrated 18/18 against GNU bash 5.3.20. Local test execution deferred to the main session's batch compile per the compile-rationing ruling; see the cluster REPORT.md for the verification ledger. Refs #2233
…l SIGHUP trap key, settled poll, real job pgrps (Refs #2233) Batch adjudication of PR #2254's interactive-target reds — all four verdict (a) product gaps, no pin or expectation changes (GNU bash 5.3.20 control cells in the adjudication REPORT reproduce every contested expectation): - run_interactive_stdin's Ok(0) arm folded a master-close hangup into a graceful exit: on Linux the dead slave reads EOF, not EIO, and only the Err arm polled the hangup queue. The EOF arm now classifies a pending untrapped hangup before folding (no `exit` echo; finish_shell settles: jobs, EXIT trap, die_by_sighup). - poll_untrapped_hangup looked the trap up as "HUP"; the trap table keys by the canonical "SIGHUP" spelling, so a trapped hangup read as untrapped. Canonical key now; the single-drain classification is factored into classify_drained_hangup. - The mailbox queues SIGHUP asynchronously and under load the queueing lag outlasts the plain poll's 5 ms settle (the exit-trap leg raced 0/129, never -1): the new poll_untrapped_hangup_settled drains until the delivery lands (100 ms budget), invoked only when the terminal is known dead (POLLHUP/POLLERR on fd 0, or an EIO read), and finish_shell re-takes the mark after the EXIT trap so a mid-finish hangup still dies by the signal instead of exiting 129. - Async direct external spawns under job control never called setpgid: the job table recorded pgrp = first pid but the process stayed in the shell's group, so hangup_all_jobs killpg'd a nonexistent group and the kernel's leader-exit SIGHUP killed jobs with or without huponexit (the huponexit-off control failed; the on leg passed vacuously). The child now takes its recorded group in pre_exec — GNU jobs.c:2390 make_child child arm setpgid(mypid, pipeline_pgrp). Verification (adjudication workdir): cargo test --test interactive 22 passed / 0 failed twice (batch baseline 18/4); the pty driver passes 18/18 in six consecutive sweeps; GNU control cells match on every leg.
Conflict resolution (compound_exec.rs, one hunk): the branch's Gap-2 pre_exec setpgid at the direct async spawn site is dropped — master's rubash#2241 wiring (1909f37, PR #2251) already composes reset + setpgid there (child_pre_exec_reset_grouped) and adds the parent-side group_spawned_child the branch lacked. An explanatory comment marks the spot; the composed diff vs master for this file is that comment only. All other #2233 changes (EOF-arm hangup classification, canonical SIGHUP trap key, settled poll, finish_shell mark re-take) merge unchanged. Refs #2233.
|
Collector merge note (224ce26): merging current master in conflicted in exactly one hunk of Remaining merge gate on my side: re-run |
WIP: hangup (SIGHUP) settlement for rubash#2233 — a shell whose controlling terminal hangs up mid-session (pty master closed) now dies BY SIGHUP where GNU does, instead of folding the terminal's EIO into a graceful EOF exit and orphaning its jobs.
What was missing (three layers, all measured against GNU bash 5.3.20 in the issue's own probe wiring):
tty_nr=0), so the kernel delivered no SIGHUP on hangup at all.acquire_controlling_terminalmirrors GNUgeneral.c:651 check_dev_tty(called frommain,shell.c:410) and runs fromrun_mainand at the interactive reader's entry.sig.c:128/sig.c:315-316), the three mailbox drains share one hangup verdict (termsig armed = interactive, or an EXIT trap armed in any shell), andfinish_shellruns the funnel in termsig order —hangup_all_jobs(jobs.c:1783, interactive gate persig.c:621-622), EXIT trap, then death BY the signal (kill_shell,sig.c:649).parse.yshell_getc, FATAL_READERROR) —script file read error+ exit 128.huponexitin an interactive login shell now hangs jobs up on normal exit (shell.c:1017-1020), after the EXIT trap.Regression pins:
tests/interactive/hangup_pty.rs+tests/interactive/support/pty_hangup_probe.py— 18 legs across the script route, the-iinteractive route, and login huponexit (job groups isolated withset -m). The driver is calibrated 18/18 against GNU bash 5.3.20 itself; baseline-red was verified against the pre-fix binary for the core legs (exit-0 folds, job survival, huponexit survival).Verification note: per the compile-authority rulings (2026-10-31 00:33 + 00:35), this cluster delivers code + pins only — the final tree saw one in-flight slot build finish (rc=0, artifact verified) under the first ruling and is rustfmt-clean, but no test build or probe run was performed on it locally. Batch compile, test/probe execution, adjudication, and merge all belong to the main session (plus this PR's CI). Full evidence ledger: cluster REPORT.md in
~/workspace/fix-2233-sighup/.Refs #2233