Skip to content

fix(jobs): BASHPID in async subshell, jobs -x pgrp, suspend -f - #1152

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/job-trio-clean
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/job-trio-clean

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1095, closes #1096, closes #1097. (1) Async ( ) did a wrapper-spawn plus an in-process parens re-entry, reporting BASHPID=pid+1; now the spawn absorbs the outermost parens (serialized inner list; guarded corners keep the old shape) with __RUBASH_BG_DEPTH/BASHPID_BASE seeding, BASHPID=pid+depth-origin (also fixes async non-paren BASH_SUBSHELL). GNU execute_cmd.c:701 single-fork semantics. (2) jobs -x now substitutes the pgroup id (jobs.c:649, recorded at fork; shell's own pgrp when no job control), bad specs pass through per GNU. (3) suspend -f does killpg(SIGSTOP) on unix (GNU suspend.def), bare suspend still errors rc=1. Tests: lib 694 + new/rewritten executor_tests + linux-gated suspend cli green, executor_tests delta-free vs clean tree; GNU parity (self-kill rc=143 stable, pgid values, suspend T-state) byte-identical.

…h#1095 #1096 #1097)

GNU runs an async `( list )` through a SINGLE make_child fork — the fork IS
the subshell (execute_cmd.c:701) — so get_bashpid = getpid()
(variables.c:1511) equals the parent's $!. The wrapper spawn already is that
fork, but the child re-entered the parens in-process (subshell_depth + 1)
and reported pid + 1. The spawn now absorbs the outermost `( list )`
(serializing the inner list; guarded on no assignments / no surviving outer
redirects or heredoc payloads) and seeds the child's depth plus a
BASHPID-origin level via __RUBASH_BG_DEPTH / __RUBASH_BG_BASHPID_BASE, so
BASHPID = pid at the spawn-realized level and pid + offset only for deeper
in-process levels. This also corrects $BASH_SUBSHELL for async non-paren
bodies (`{ }; &`, simple `&` report 1, probed GNU 5.3.20).

ID (builtins/jobs.def execute_list_with_replacements `itos (j->pgrp)`;
POSIX jobspec -> pgroup). JobEntry records pgrp at fork time (jobs.c:649):
first pipeline pid with job control, else the shell's own pgrp
(jobs.c:2455-2461; read via getpgid(0) on unix). Bad specs pass through
unchanged with the command's own status, per the same GNU function
(INVALID_JOB -> continue); `jobs -p`/`-l` already print real pids and are
untouched.

no-job-control/login guards under -f and stops its own process group
(`killpg (shell_pgrp, SIGSTOP)`, builtins/suspend.def), returning SUCCESS
once continued. The -f path now does getpgid(0)+killpg(SIGSTOP) on unix
(SIGSTOP/SIGCONT ride kernel defaults, never in the managed set); bare
`suspend` still reports `cannot suspend: no job control` (rc 1) and
non-unix keeps the historical no-op.

Verification (bash 5.3.20 oracle vs script files): #1095 child-self == $!
and self-TERM rc=143; #1096 prints the pgid; #1097 T-state then rc=0 after
CONT — all byte-identical to GNU. Focused suites green: lib 694/694,
executor part_035/part_005 (incl. 3 new/rewritten tests), new linux-gated
cli suspend test. Full executor_tests shows only the 13 pre-existing
Android-environment failures, identical on unmodified origin/master.
@caomengxuan666
caomengxuan666 merged commit e743db8 into master Oct 23, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

Rebased onto post-#1181 master and force-pushed as cda7cf4a. One conflict in init.rs: merged master's __RUBASH_SUBSHELL_DEPTH seed (#1074) with this PR's __RUBASH_BG_DEPTH — BG_DEPTH wins for async & children (it deliberately under-seeds when serialized parens still bump in-process), respawned marker covers coproc/other respawns. 61/63 focused executor tests green; the 2 failures (test_cd_pwd_command_substitution_accepts_semicolon_separator, test_jobs_unknown_jobspec_reports_failure) reproduce identically on unmodified master — pre-existing Windows env issues, not regressions.

@caomengxuan666
caomengxuan666 deleted the fix/job-trio-clean branch October 23, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant