Skip to content

WIP: fix(suspend): key the no-job-control gate on the job_control variable - #2498

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2487-suspend-monitor-mode
Nov 1, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2487-suspend-monitor-mode

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2487

What

suspend in a non-interactive script that ran set -m was refused with cannot suspend: no job control, because the builtin's gate never saw the monitor state. GNU keys the builtin on the job_control variable (jobs.c:223), not the flag: suspend_builtin (builtins/suspend.def:80-126) checks the variable (then the login-shell guard) only when -f is absent, and the variable is fed by set -m/set +m through flags.c:257's set_job_control call — while every fork boundary erases only the variable (jobs.c:5356-5366 without_job_control), leaving the m letter in the child's $-. Command substitution is the exception: its fork keeps the variable (subst.c:7143).

Change

  • ShellState::job_control: Cell<bool> models the variable, beside subshell_login_cleared whose boundary discipline it shares.
  • Writers: the set builtin's monitor writes (o_writes replay in execute_set; short-flag writes now recorded by set_with_io_tracked; the two fast set arms sync via a word scan) and Executor::set_shell_option (startup/API funnel — CLI -m, interactive defaults, terminal-failure drop).
  • Boundary resets: flat ( ) region entry (ast_exec), scoped subshell entry (compound_exec), stripped-parens bracket (command_substitution), pipeline stage bracket (pipeline_exec), the three cloned pipeline stage executors (pipeline_stages); respawned processes start false (init).
  • execute_suspend passes the variable + effective login state into suspend::execute_with_io; the stop machinery itself is byte-identical, moved verbatim under the GNU-order guards.

Verification

  • r46 differential set (60 cases, GNU bash 5.3.20 oracle, runner_r46.py): frozen master verdict 38 SAME / 22 DIFF → this branch 56 SAME / 4 DIFF. All 18 suspend-gate cells flip; no new diffs. Remaining diffs are pre-existing and outside the gate: ss27 (foreground-job stop handling in wait_for), ss12 (CONT-trap shadowing by suspend_continue), jr09/jr13 (jobs warning faces) — classified in the cluster REPORT for separate homing.
  • New pins tests/issue2487_suspend_job_control_gate.rs: 11/11 under scrubbed fds (harness: setsid session + /proc T-state proof + SIGCONT pulse rescue, modeled on tests/issue1474 / runner_r46.py — no pty harness).
  • tests/issue1474_suspend_timing_regressions: still green. cargo check --lib --bins --tests: clean.

… (rubash#2487)

GNU's suspend_builtin (builtins/suspend.def:80-126) reads the
job_control VARIABLE (jobs.c:223), not the monitor flag: the guards
fire only when !force, in source order — job_control == 0 ->
sh_nojobs + EXECUTION_FAILURE (suspend.def:103-107), then
login_shell -> "cannot suspend a login shell" (suspend.def:109-113)
— before killpg (shell_pgrp, SIGSTOP) and EXECUTION_SUCCESS.

The variable shadows the flag only at write/startup time:
flags.c:257 routes set -m/set +m through set_job_control
(jobs.c:5318-5325); shell.c:647 seeds set_job_control
(interactive_shell), shell.c:1858 from the -m invocation flag. A
fork boundary erases ONLY the variable (jobs.c:5356-5366
without_job_control, called from execute_cmd.c's
execute_in_subshell and execute_subshell_builtin_or_function):
( ) regions, pipeline elements, and &-job bodies refuse even
under an outer set -m, while $- keeps the m letter. The
command-substitution fork keeps the variable (subst.c:7143
command_substitute never touches it).

Model the variable as ShellState::job_control (a Cell beside
subshell_login_cleared, whose boundary discipline it shares):
- writers: the set builtin's monitor writes (recorded into the
  o_writes replay in execute_set, with short-flag -m writes now
  recorded by set_with_io_tracked; the two fast set arms sync via
  a word scan), and Executor::set_shell_option (the startup/API
  funnel: CLI -m, interactive defaults, and the job-control
  terminal failure that drops the option again);
- boundary resets (set false): the flat ( ) region entry in
  ast_exec, the scoped subshell entry in compound_exec, the
  stripped-parens bracket in command_substitution, the pipeline
  stage bracket in pipeline_exec, and the three cloned pipeline
  stage executors in pipeline_stages; a fresh process (respawn)
  starts false in init;
- reader: execute_suspend passes the variable and the effective
  login state (invocation_login && !subshell_login_cleared,
  execute_cmd.c:1636-1637) into suspend::execute_with_io, whose
  stop machinery is unchanged (moved verbatim under the guards).

Verification (GNU bash 5.3.20 oracle, r46 runner): the frozen
master verdict was 38 SAME / 22 DIFF over the 60-case r46 set;
with this change 56 SAME / 4 DIFF — all 18 suspend-gate cells
flip and no new diffs appear. The remaining diffs are
pre-existing and outside the gate: ss27 (foreground-job stop
handling in wait_for), ss12 (CONT trap shadowing by
suspend_continue), jr09/jr13 (jobs warning faces).
New pins tests/issue2487_suspend_job_control_gate.rs: 11/11
under scrubbed fds; tests/issue1474_suspend_timing_regressions
still green.

Refs #2487
@caomengxuan666
caomengxuan666 force-pushed the fix/2487-suspend-monitor-mode branch from a6cf8a3 to 073354e Compare November 1, 2026 22:25
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 1, 2026 23:38
@caomengxuan666
caomengxuan666 merged commit 746759d into master Nov 1, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2487-suspend-monitor-mode branch November 2, 2026 01:10
@caomengxuan666

Copy link
Copy Markdown
Member Author

[win-acceptance] #2498 PASS — pin issue2487_suspend_job_control_gate is #![cfg(target_os = "linux")] (setsid + /proc T-state proof machinery) — 0 tests on Windows by design, so verification is live-probe based: set -m; echo before; (sleep .8; kill -CONT $$)&; suspend; echo after; echo rc=$?; wait → rubash byte-identical to WSL GNU Bash 5.3.20 (stops, is CONT-rescued, prints after/rc=0/done in the same order, no cannot suspend diagnostic); bare-suspend refusal face (suspend no -m in non-interactive script) identical diagnostics and rc.

Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 9348b8d (contains this merge), GNU oracle = wsl /usr/local/bin/bash 5.3.20 script-file comparison; probes D:/repo/win-accept/wave2/probes/p2487.*. No BLOCKER.

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