Repository navigation
fix(jobs): async non-paren & bodies run one subshell level down - #1249
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).