Skip to content

WIP: fix BASHPID origin seeding at input-procsub producer and coproc respawns - #2243

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1582-bashpid
Oct 30, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1582-bashpid

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1582

What this fixes

A real bug family distinct from the flat-layer $BASHPID projection
tradeoff: two fork-shaped respawn sites seeded the child's subshell
DEPTH but not its BASHPID ORIGIN base, so a real process's own
$BASHPID read its real pid + 1.

GNU ground truth: BASHPID is getpid() of the reading shell
(variables.c:1511); a process-substitution producer / coproc body is
a forked shell in its own right (subst.c:6362), so its BASHPID must
equal its real pid and the PPID of children it spawns.

Respawn-site audit (all four sites):

site depth stamp origin-base stamp
async wrapper yes yes (already correct)
output-procsub consumer yes yes (already correct)
input-procsub producer (trap_exec.rs) yes no -> fixed
coproc shell route (compound_exec.rs) yes no -> fixed

Raw-value proof (pre-fix binary): coproc body BASHPID 143606 vs
body-child PPID 143605 (parent-known pid 143605); input-producer
body BASHPID 139055 vs its child PPID 139054. Post-fix: all equal,
matching GNU.

The fix stamps __RUBASH_BG_BASHPID_BASE with the same value as the
__RUBASH_SUBSHELL_DEPTH stamp at each site, mirroring the
output-procsub consumer's existing pair.

Regression pins (tests/regression.rs, mod issue_1582)

Three-way checks (body BASHPID == body-spawned child PPID ==
parent-known pid), GNU expectations:

  • issue1582_coproc_bashpid_matches_child_ppid — red on baseline
  • issue1582_input_procsub_producer_bashpid_matches_child_ppid — red on baseline
  • issue1582_output_procsub_consumer_bashpid_matches_child_ppid — guard pin for the already-correct site

Baseline-red verified by stash comparison (product diff stashed,
pins kept): the two target pins fail, the guard and the three
pre-existing issue1582 contract pins pass. On the fixed tree the
issue1582 module is 6/6 green; neighbor sets (issue_1584,
issue_1951, issue_1952, issue_1646) green except
issue1584_named_coproc_pid_is_the_program, which is red on the
stashed baseline in this Linux environment as well (pre-existing,
unrelated to this change).

What this does NOT do

The flat (in-process) subshell BASHPID projection
(pid + depth offset) is unchanged. Its remaining divergences from
GNU are the adjudicated design surface recorded in the cluster
report (projection map + battery): at most two of {BASHPID ==
children's PPID, layers mutually distinct, kill $BASHPID scoped to
own layer} can hold in a no-fork model. The contract pin
issue1582_kill_own_bashpid_stays_scoped_to_the_subshell continues
to pass unchanged.

…d coproc respawns

Refs #1582

Two fork-shaped respawn sites seeded __RUBASH_SUBSHELL_DEPTH for the
child shell but not __RUBASH_BG_BASHPID_BASE, so the child's own
$BASHPID read its real pid + 1 (depth offset applied on top of the
real pid). GNU: BASHPID is getpid() of the reading shell
(variables.c:1511), and a process-substitution producer / coproc body
is a forked shell in its own right (subst.c:6362), so its BASHPID must
equal its real pid and its children's PPID.

Audit of all four respawn sites: the async wrapper and the
output-procsub consumer already stamp both carriers; the
input-procsub producer (trap_exec.rs) and the coproc shell route
(compound_exec.rs) stamped depth only. Both now stamp
__RUBASH_BG_BASHPID_BASE with the same value as the depth stamp,
mirroring the consumer site's pair.

Regression pins (tests/regression.rs, mod issue_1582), all
three-way BASHPID == child-PPID == parent-known-pid checks:
- issue1582_coproc_bashpid_matches_child_ppid (red on baseline)
- issue1582_input_procsub_producer_bashpid_matches_child_ppid
  (red on baseline)
- issue1582_output_procsub_consumer_bashpid_matches_child_ppid
  (guard for the already-correct site)

The flat-layer synthetic BASHPID projection itself is unchanged;
its remaining divergences are an adjudicated design surface, not
touched here.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 16:04
@caomengxuan666
caomengxuan666 merged commit 830051f into master Oct 30, 2026
13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1582-bashpid branch November 2, 2026 01:08
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.

1 participant