Repository navigation
#2398 foreground job stop detection (WUNTRACED wait + tcsetpgrp handoff) - #2406
Conversation
Spec-first pins for the Ctrl+Z execution face. GNU contract (bash 5.3 jobs.c): waitchld waits with WUNTRACED under job control (jobs.c:4077), give_terminal_to (jobs.c:4999) hands the tty to the child pgrp, and a stopped job becomes current with $? = 128+WSTOPSIG (jobs.c:3243). Verified against the local 5.3.20 oracle in a pty: sleep 30 + ^Z -> '[1]+ Stopped sleep 30', RC=148, fg resumes, ^C -> RC=130. Refs #2398
The stop-detection channel for interactive job control, per GNU bash 5.3 jobs.c: - Gate (job_control_wait::job_control_channel_active): interactive + monitor + top level (jobs.c:4077 subshell_environment == 0) + controlling tty present. Spawn, wait, and fg share the predicate. - Spawn: job-control foreground children lead their own pgrp (pre_exec setpgid, jobs.c:2390/2446; parent repeats it after the fork, jobs.c:2455) — previously the child shared the shell's group, so ^Z stopped the shell too. - Wait (wait_fg_child_job_control): the job is registered before the wait, the terminal is handed to its pgrp (give_terminal_to, jobs.c:4999), and a sliced waitpid(WUNTRACED|WNOHANG) observes the stop: job marked Stopped + current (waitchld bookkeeping), flipped to a background-listed job, handle parked in background_children, boundary stop notice queued, wait verdict 128+stopsig (jobs.c:3243). Terminal reclaimed on every exit path (jobs.c:3253). Exit path deletes the job, as GNU does for a completed foreground job. - fg (execute_fg_jobs): give_terminal_to(job pgrp) before SIGCONT (jobs.c:3918/3926), WUNTRACED wait (wait_for_fg_job_control) so a re-stop is an outcome, reclaim after (jobs.c:3253). - bg/wait need no changes: the stopped job sits in the table + background_children in the shape their existing paths consume. - Emulated sleep stands down to a real spawn while the channel is live — GNU's sleep is a job-controlled child; the in-process emulation has no pgrp to stop or resume. - Stop notice renders at the reader boundary inside report_pending_signal_notices, jobs short format, ahead of death notices. All unix machinery is cfg-gated; the Windows target keeps the existing paths. Not yet verified (check + PTY pins pending). Refs #2398
36b1c28 to
0bb54d0
Compare
…the wait Two field corrections from the first PTY runs: - The stdio plan arms an ExternalStdioOutcome for EVERY planned spawn (LiveHandles for the plain shape), so an is_none() gate never fired. The channel now claims every non-CapturePipe spawn, and the WUNTRACED wait is dispatched in the LiveHandles branch as well as the no-outcome plain branch. CapturePipe shapes keep the existing waits. - The stop notice cannot ride the command-boundary flush (report_pending_signal_notices runs when the NEXT command is walked — a full prompt after GNU's position). GNU reports the foreground job's stop as wait_for completes (jobs.c:3385 notify_and_cleanup), so the foreground wait now prints it synchronously via format_stopped_job_notice, and fg's re-stop notice rides fg's own stderr Vec (after the command text it printed, in wait_for's order). The boundary queue is gone. Refs #2398
…orrow fg's command text flushes when the builtin returns (the repo's builtin-output plumbing — verified identical on master with a background job), so the pin now asserts the resume by natural completion (FGRC=0, text in transcript) on a short job, then runs the ^C-kills-the-resumed-job cycle (RC2=130) as a second phase. Also fix the finish()/text() use-after-move the first build hit. Refs #2398
|
Status from the fix cluster (head 58b8746, rebased on master 7f682e0): Scope — only the fg-recovery face of #2398, per coordination: stop detection in the interactive foreground wait + job Stopped bookkeeping + terminal hand-back, so Mechanism (GNU bash 5.3 jobs.c citations in the commits):
Local verification so far (compile rationing; full batch is the collector's):
Residuals (named, not filed): foreground PIPELINES as stoppable jobs (stage waits live in the pipeline spawner); fd-copy-capture foreground face; subshell-depth>0 foreground face (flat-model two-table shape); background jobs stopped by an external killer are still learned only via the kill-path deferred marks + boundary refresh (no background WUNTRACED poller); other emulated externals besides sleep under job control; Stays draft; do not merge from here. |
Refs #2398
Job control: a foreground child's SIGTSTP stop is invisible to the shell — the interactive foreground wait has no WUNTRACED and there is no tcsetpgrp handoff, so ^Z stops the shell's whole process group (shell shares the child's pgrp) and the session freezes; jobs/fg report "no job control".
GNU contract (bash 5.3 sources, verified against the local 5.3.20 oracle in a pty):
This first commit lands the end-to-end PTY pins only (tests/issue2398_jobstop_regressions.rs): ^Z via the pty VSUSP path, stop notice + RC=148 + jobs listing, fg resume + ^C -> 130, bg resume path. Implementation follows in increments on this branch.
Out of scope: prompt-side ^Z (reedline Undo, settled design); #2396/#2397 exit-time checkjobs (sibling cluster).