Skip to content

[P3][env] wait -p / coproc 路径 unbind 残留(与 #943 同源) - #1180

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/971-wait-coproc-unbind
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/971-wait-coproc-unbind

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #971

Summary

Extends #943's unbind discipline (unset_process_env) to the two paths the
review flagged: wait -p's variable-capture unbind and the coproc unbind
channel. Both removed the table entry but left the inherited process-env
copy, the typed cell, and the attribute bits — so exact_case_env_var
bare-$NAME reads, nounset boundness, arithmetic, and declare -p all
resurrected residue that GNU makunbound (variables.c:3959) disposes
wholesale (variables.c:3839 drops the export-env copy unconditionally).

  • execute_wait (job_builtins.rs): faithful builtin_unbind_variable
    port (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 and
    the operand is makunbound literally. A bracketed operand is a literal
    name there: wait -p 'A[0]' no-ops (the old unset_array_element
    call 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-mark
    branch, 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 and
    all attribute bits; the __RUBASH_COPROC_{STDIN,STDOUT}_<pid> fd-channel
    bookkeeping keys are dropped with them.
  • retire_completed_coproc: __RUBASH_FD_* bookkeeping removals get the
    same unset_process_env sweep (inherited mirror copies qualify as
    __RUBASH_ special names).

Probes vs WSL GNU bash 5.3.20 (script files, not wsl bash -c)

  • WP=parent env: wait -p WP -> [unset] (was [parent]); set -u
    aborts with WU: unbound variable; wait -n -p no-candidate rc=127
    leaves [].
  • wait -p 'A[0]' on scalar/array/readonly array: operand intact (GNU
    literal 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 variable rc 1; dead chain unbinds the operand. wait -p BASH_SOURCE
    -> cannot unset rc 1; wait -p LINENO stays unbound.
  • Inherited CP/CP_PID (+ unnamed COPROC): after reap [][],
    $((CP_PID+0)) -> 0, declare -p reports not found (no declare -x
    residue).

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.
  • Neighbors: issue352/387/549/550 (coproc/jobs) + issue529/534/535/
    538/638/639/645/651/705 (env/unset/nounset) all green.
  • cargo fmt --check clean; cargo build clean (also rebuilt and
    retested on latest master in a clean worktree).
  • coproc.tests slice: coproc fd lines (63 60 x3) and REFLECT 143
    match coproc.right; remaining diffs are pre-existing env-bound
    (xcase, /etc/passwd) on Windows.

Generated with Devin

…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>
@caomengxuan666
caomengxuan666 merged commit f544e27 into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/971-wait-coproc-unbind 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.

[P3][env] wait -p / coproc 路径 unbind 残留(与 #943 同源)

1 participant