Skip to content

fix(jobs): async non-paren & bodies run one subshell level down - #1249

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

caomengxuan666 merged 1 commit into
masterfrom
fix/reopen-job

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1074 (residual). GNU execute_cmd.c:1588 execute_in_subshell unconditionally bumps subshell_level in the forked child — every & body goes one level down. rubash's generic & respawn seeded non-paren bodies at parent depth (only stripped parens and coprocs got +1). Fix: strip_parens || no-subshell-command -> parent+1; unstripped parens keep parent (in-process bump applies). #1023 investigated with evidence: premise wrong — GNU keeps both arrays under MULTIPLE_COPROCS (only reaps on teardown), deterministic sleep probes byte-identical; no change, matches #1181 conclusion. #1097 verified already-correct (killpg STOP, setsid probes match). Tests: lib 712 + 4 new + coproc/subshell/background suites green; GNU parity byte-identical. One pre-existing env failure (path walk /tmp permission, fails on clean master too).

…bash#1074)

GNU execute_cmd.c:1588 execute_in_subshell runs subshell_level++ in the
forked child for EVERY async body — simple commands, `{ }` groups,
`( )` lists and coproc bodies alike. The generic `&` respawn seeded
__RUBASH_BG_DEPTH with the parent level for all unstripped bodies, so
`echo $BASH_SUBSHELL &` and `{ echo $BASH_SUBSHELL; } &` reported 0
instead of 1 (the coproc spawn already seeded parent + 1, and stripped
`( )` absorbed the fork, so those two shapes were already correct).

Seed parent + 1 for every background body except an UNSTRIPPED paren
node, which still bumps in-process via
execute_subshell_command_with_redirects (init.rs prefers BG_DEPTH, so
only this site changes).

Verified byte-identical vs GNU bash 5.3.20 (script-file対拍):
`echo &` sq:1, `{ } &` brace:1, `( ) &` paren:1, nested `( & )` 2,
coproc cpbody:1, top-level stays 0.

Notes (no code change, verified only):
- rubash#1023: with MULTIPLE_COPROCS=1 (config-top.h:142-143)
  execute_coproc never tears anything down at creation (cpl_add only);
  disposal is cpl_reap at stop_pipeline/cleanup_dead_jobs
  (execute_cmd.c:2166 coproc_dispose -> :2450 coproc_unsetvars). A
  back-to-back echo probe shows GNU keeps BOTH arrays after the second
  creation (A1=63 A2=62), same as niu. The deterministic sleep-1 case
  is byte-identical on both (both ambiguous, rc=1, via #1198); the
  sleep-less case is a reap race on the GNU side itself (4/5 first-ok
  vs 1/5 both-ambiguous), so emulating it would break working
  multi-coproc support (cf. #1181).
- rubash#1097: `suspend -f` already stops (T state via killpg SIGSTOP)
  and resumes with rc=0 on CONT, matching GNU; no change.

Tests: new tests/issue1074_bg_subshell_depth.rs 4/4; cargo test
--lib 712/0; coproc/subshell/background slices green
(352/387/971/100/336). issue866 w1 #737 still fails identically on
pristine origin/master (pre-existing env issue, untouched).
@caomengxuan666
caomengxuan666 merged commit d3d24bb into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/reopen-job branch October 23, 2026 08:54
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.

[bug] BASH_SUBSHELL is 0 in async background jobs and coproc bodies

1 participant