Repository navigation
[P3][env] wait -p / coproc 路径 unbind 残留(与 #943 同源) - #1180
Merged
Merged
Conversation
…971) The wait -p variable-capture unbind (job_builtins.rs execute_wait) and the coproc unbind channel (coproc_unset_vars) removed the variable-table entry but left the inherited process-env copy — the same residue class #943 fixed for `unset`: a name that predates the #916 write mirror was never removed, and every table-miss fallback resurrected it (exact_case_env_var bare-$NAME reads, nounset boundness, the child-spawn env base). GNU anchors: - builtins/wait.def:166 -> builtins/common.c:1021 builtin_unbind_variable: find_variable (variables.c:2363) resolves the nameref chain, so the readonly/non-unsettable gates test the REFERENT while diagnostics name the operand; a dead chain leaves v == 0 and the operand is makunbound literally (variables.c:3788/3959). A bracketed operand is a literal name there — `wait -p 'A[0]'` never unbinds an element, so scalars and readonly arrays survive intact (the old unset_array_element call was a second, independent divergence). - execute_cmd.c:2450 coproc_unsetvars: unbind_variable_noref(<name>_PID) literal + check_unbind_variable(<name>) nameref-resolved. - variables.c:3959 makunbound disposes the whole SHELL_VAR: mirror entry, typed cell, all attribute bits (variables.c:3839 export-env drop). The unbind now also clears the typed `variables` cell and every attribute mark (the `declare -x CP` residue is gone), records UNSET_DYNAMIC_VARS for dynamic names, routes visible locals through makunbound's invisible-mark branch (unset_outer_local_variable), and drops the __RUBASH_COPROC_*_<pid> fd-channel bookkeeping keys. Probes vs WSL GNU bash 5.3.20 (script files): wait -p/-n -p on inherited names -> unbound (set -u aborts), bracketed operand is a literal no-op, nameref unbinds the referent (readonly referent: `wait: ref: cannot unset: readonly variable`), non-unsettable BASH_SOURCE errors, LINENO stays unbound, function-local -> `declare --` invisible, coproc CP/COPROC and *_PID unbound with arith fallback 0. Regressions: tests/issue971_wait_coproc_unbind_env_regressions.rs — 12 tests, 11 fail pre-fix. Neighbors green: issue352/387/549/550 + unset/env/nounset files. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Fixes #971
Summary
Extends #943's unbind discipline (
unset_process_env) to the two paths thereview flagged:
wait -p's variable-capture unbind and the coproc unbindchannel. Both removed the table entry but left the inherited process-env
copy, the typed cell, and the attribute bits — so
exact_case_env_varbare-
$NAMEreads, nounset boundness, arithmetic, anddeclare -pallresurrected residue that GNU
makunbound(variables.c:3959) disposeswholesale (variables.c:3839 drops the export-env copy unconditionally).
execute_wait(job_builtins.rs): faithfulbuiltin_unbind_variableport (builtins/common.c:1021 via wait.def:166).
find_variable(variables.c:2363) resolves namerefs, so the readonly/non-unsettable
gates test the referent while diagnostics name the operand; a dead
chain (missing/element/circular target) is
v == 0— gates skip andthe operand is makunbound literally. A bracketed operand is a literal
name there:
wait -p 'A[0]'no-ops (the oldunset_array_elementcall wrongly unbound the element — verified: GNU keeps scalars and
readonly arrays intact). The unbind itself is now a real makunbound:
env_vars +
variables+unset_process_env+remove_unset_marks,with locals routed through
unset_outer_local_variable(invisible-markbranch, variables.c:3984-4005) and dynamic names recorded in
UNSET_DYNAMIC_VARS.
coproc_unset_vars(execute_cmd.c:2450):<name>_PID(noref literal)and
<name>(resolved, readonly-gated) now drop process-env copies andall attribute bits; the
__RUBASH_COPROC_{STDIN,STDOUT}_<pid>fd-channelbookkeeping keys are dropped with them.
retire_completed_coproc:__RUBASH_FD_*bookkeeping removals get thesame
unset_process_envsweep (inherited mirror copies qualify as__RUBASH_special names).Probes vs WSL GNU bash 5.3.20 (script files, not
wsl bash -c)WP=parentenv:wait -p WP->[unset](was[parent]);set -uaborts with
WU: unbound variable;wait -n -pno-candidate rc=127leaves
[].wait -p 'A[0]'on scalar/array/readonly array: operand intact (GNUliteral
makunbound("A[0]"));unset 'A[0]'still removes the element.wait -p ref(ref->target): target unbound,declare -n ref="target"survives; readonly target ->
wait: ref: cannot unset: readonly variablerc 1; dead chain unbinds the operand.wait -p BASH_SOURCE->
cannot unsetrc 1;wait -p LINENOstays unbound.CP/CP_PID(+ unnamedCOPROC): after reap[][],$((CP_PID+0))-> 0,declare -preports not found (nodeclare -xresidue).
Test plan
tests/issue971_wait_coproc_unbind_env_regressions.rs— 12 tests,11 fail on the pre-fix binary (verified via stash), all pass after.
538/638/639/645/651/705 (env/unset/nounset) all green.
cargo fmt --checkclean;cargo buildclean (also rebuilt andretested on latest master in a clean worktree).
63 60x3) and REFLECT 143match
coproc.right; remaining diffs are pre-existing env-bound(
xcase,/etc/passwd) on Windows.Generated with Devin