Repository navigation
WIP: respawn transport-set completeness: fork-state census + shared transport (rubash#2058) - #2188
Merged
Merged
Conversation
Refs #2058 Fork-state census for respawn children (process-substitution bodies, async & function bodies, coproc bodies), probed shape-by-shape against GNU bash 5.3.20 at script top level, inside a function, and inside a function under extdebug. Each fork-inherited item gets a three-state verdict (TRANSPORT / PROJECT / DELIBERATELY-OMIT): - TRANSPORT, already landed: positional params (#2032), SECONDS, BASH_SUBSHELL, non-exported variables and local values (env merge). - TRANSPORT, open: BASH_ARGV/BASH_ARGC frames and bottom frame (variables.c:1656 get_bashargcv / :5643 init_bash_argv semantics, including the unmaterialized state), FUNCNAME/BASH_SOURCE/ BASH_LINENO stacks, PIPESTATUS at fork time, SHLVL (a fork is not a new shell), LINENO start for body-text shapes. - PROJECT: $$/BASHPID/$!/$PPID per the #1582 ruling; the coproc spawn site lacks the __RUBASH_SHELL_PID stamp its siblings carry. - DELIBERATELY-OMIT: RANDOM/SRANDOM sequences — variables.c:1412 get_random_number reseeds in a subshell environment, so GNU itself carries no sequence across the fork; the contract is parent-untouched plus child-fresh. Implementation follows as one shared transport mechanism at the four spawn sites; see the issue for the full census table.
…nd SHLVL to respawn children Refs #2058 GNU's fork-shaped children inherit the parent's call-stack arrays and PIPESTATUS cell verbatim (variables.c; subst.c:6362 process_substitute, execute_cmd.c:1576 execute_in_subshell, coproc make_child). The respawn transport set carried only the positional window (#2032); this closes the rest of the census (docs/design/respawn-transport-census.md) with one mechanism: - One stamp builder, Executor::fork_context_transport_entries, merged at all four spawn sites next to the positional stamp: the parent's effective FUNCNAME/BASH_SOURCE/BASH_LINENO views, BASH_ARGV/BASH_ARGC frames, the materialized bottom frame under a presence-keyed stamp (variables.c:1656 get_bashargcv: an unmaterialized array stays unmaterialized in the child when the fork happened inside a function), in-function / main-frame flags, and the PIPESTATUS cell via the existing state codec. The stamp peeks the bottom frame — a fork does not materialize the parent's arrays, so the stamp must not either. - One consumption site at Executor birth (provenance-gated, stripped unconditionally): frames land in ShellState::inherited_fork_frames and the four dynamic views compose the child's own frames above them; the bottom frame seeds bash_arg_bottom; the cell seeds the PIPESTATUS fields. Nested respawns re-stamp the composed views. - SHLVL: a fork is not a new shell, so a validated respawn keeps the parent's value (initialize_fresh_shell_env_vars keep_shlvl); the exec replacement path keeps the increment. - The coproc site gains the __RUBASH_SHELL_PID stamp its siblings carry, so the child's $$ takes the #1582 projection. - LINENO seeds at the async-wrapper and coproc sites now name the first leaf command's line (a compound node's own line is its closing line), and the async wrapper's line offset compensates the function prelude's newline count like the output-procsub consumer site already did. Regression pins: tests/issue2058_respawn_transport_regressions.rs (12 pins, one per census item, GNU 5.3.20 expectations). Local: lib 970/0, procsub/coproc neighborhoods green, cli_tests compat + process_substitution filters show only the two pre-existing #2175 wrong-pin history failures also present on master.
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.
Refs #2058
Phase 1 — census (first commit)
Fork-state census for respawn children (process-substitution bodies,
async
&function bodies, coproc bodies), probed against GNU bash5.3.20 across 21 shape×context probes (script top level / inside a
function / inside a function under
extdebug):docs/design/respawn-transport-census.md.BASH_SUBSHELL, non-exported variables and local values, cwd, umask, $0.
(incl. the unmaterialized state — variables.c:1656
get_bashargcv,:5643
init_bash_argv), FUNCNAME/BASH_SOURCE/BASH_LINENO stacks,PIPESTATUS at fork time, SHLVL, LINENO start for body-text shapes.
site was missing its
__RUBASH_SHELL_PIDstamp; added.get_random_numberreseeds in a subshell environment, so GNU itselfcarries no sequence across the fork (parent-untouched + child-fresh
already holds; pinned).
Phase 2 — one shared transport mechanism
Executor::fork_context_transport_entriesbuilds the__RUBASH_FORK_*stamp once; all four spawn sites (async/subshellwrapper, coproc, procsub consumer, procsub producer) merge it next
to the 回归:bats 在 rubash 下零测试执行(文件名空白 + gather trace 文件消失),窗口 (46452a9e, e9802c0c](生态审计 DIV-D) #2032 positional stamp. The bottom frame is peeked, never
installed — a fork does not materialize the parent's arrays.
Executor::newconsumes it provenance-gated and strips itunconditionally: frames land in
ShellState::inherited_fork_frames,the bottom seeds
bash_arg_bottom, the codec-encoded cell seedsPIPESTATUS. The four dynamic views compose own frames above
inherited ones; nested respawns re-stamp the composed views.
(
keep_shlvl); theexecreplacement path keeps the increment.command's line (a compound node's own line is its closing line);
the async wrapper's offset compensates the function prelude's
newline count like the procsub consumer site already did (this
also fixes a +1 drift in BASH_LINENO call lines inside async-fn
children).
Verification
tests/issue2058_respawn_transport_regressions.rs: 12/12(one per census item, GNU expectations; baseline-red evidence is
the pre-fix census matrix on master 36dfeff with identical probes).
remaining 9 differ only in the mid-body
$LINENOscalar — thedocumented deferred item (definition/intra-body lines need
source-span transport; body start lines are exact, pinned).
cargo test --lib970/0 (master baseline); procsub/coprocneighborhoods (2179/1220/1221/1659/2053/2057) green; cli_tests
compat + process_substitution filters show only the two
pre-existing [tests] 三组回归钉期望与 GNU 不符(history 两钉 + exec 重定向钉)+ issue151 环境形钉——只改测试 #2175 wrong-pin history failures also on master.