Skip to content

WIP: SIGHUP hangup settlement — ctty acquisition, termsig funnel, huponexit - #2254

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/2233-sighup
Oct 30, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/2233-sighup

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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):

  1. No controlling terminal was ever acquired (tty_nr=0), so the kernel delivered no SIGHUP on hangup at all. acquire_controlling_terminal mirrors GNU general.c:651 check_dev_tty (called from main, shell.c:410) and runs from run_main and at the interactive reader's entry.
  2. No termsig settlement: untrapped interactive SIGHUP now pins to the signal mailbox (mirroring the SIGINT pin; 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), and 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 the signal (kill_shell, sig.c:649).
  3. Reader folds split by route, as GNU splits them: the interactive reader polls for a queued hangup (no trap dispatch) before folding a tty read error like EOF; the script reader takes the READERR arm (parse.y shell_getc, FATAL_READERROR) — script file read error + exit 128. huponexit in 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 -i interactive route, and login huponexit (job groups isolated with set -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

caomengxuan666 and others added 3 commits October 30, 2026 16:35
…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.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Collector merge note (224ce26): merging current master in conflicted in exactly one hunk of compound_exec.rs — this branch's Gap-2 bare pre_exec setpgid at the direct async spawn site vs master's #2241 wiring (1909f37: child_pre_exec_reset_grouped + parent-side group_spawned_child). Resolution: the branch hunk is dropped as subsumed (keeping it would setpgid twice; master also carries the parent-side twin). The composed diff vs master for that file is now an explanatory comment only; every other #2233 change is unchanged, and the PR's file list vs master is identical to the branch's own change set.

Remaining merge gate on my side: re-run cargo test --test interactive on the composed tree (CI does not cover that target) — the huponexit legs must re-prove against master's real grouping, since the adjudication tree predated #2251.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 22:46
@caomengxuan666
caomengxuan666 merged commit b06386b into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2233-sighup branch November 2, 2026 01:08
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