Skip to content

fix(exec): entry-poisoned shells store no logical cwd so cd prints the chdir line - #4282

Merged
caomengxuan666 merged 2 commits into
masterfrom
captain/4120-entry-poisoned-chdir
Nov 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
captain/4120-entry-poisoned-chdir

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(executor): store failed-birth logical cwd as None so the cd entry re-derivation fires

Refs #4120
UNVERIFIED-BY-CAPTAIN

Root cause

A shell born in a deleted cwd (entry poison) printed the
shell-init: line at startup but never the chdir: line on the
first cd, where GNU bash 5.3.20 prints both. The mid-session
poison (a failed pwd -P via resetpwd, rubash#3574) did print it.

The fresh-shell seed stored the failed birth capture's empty
logical cwd as Some("") (Executor::new, and the in-process
child seed in external_finish). GNU's set_pwd
(variables.c:907) leaves the_current_working_directory NULL in
this state, and the cd entry re-derivation
(builtins/cd.def:529-534 → get_working_directory ("chdir")) is
gated on exactly that NULL — rubash's logical_cwd.is_none().
Some("") read as a live base instead: no entry line, and
relative destinations were built against the empty string.

Fix

Both fresh-shell seed points now store the empty adoption as
None — the same representation the resetpwd poison already
uses, so "no logical cwd known" has a single state for every
reader (cd entry, pwd's poisoned arm, transport).

  • src/executor/init.rs: logical_cwd: (!startup_logical_cwd.is_empty()).then_some(startup_logical_cwd)
  • src/executor/external_finish.rs: same mapping for the child seed.

本 PR 删除了什么

No code deleted and no mechanism added: the birth seed is aligned
to the existing None representation instead of carrying a second
spelling (empty string) for the same state.

Net lines

Production +16/−4; tests +181 (new pin file + aggregator line).

Pins

tests/issues_3900_4199/issue4120_entry_poisoned_cd_chdir_line.rs:
entry-poisoned cd . (one chdir: line), cd . twice (still
one), cd .. (one), entry-poisoned pwd guard (unchanged face),
and the form-A self-poison guard (the verbatim arm's cd: line,
one per cd .).

Evidence

  • Oracle: cloud GNU bash 5.3.20, script-file probes. Form B
    (entry poison) before: stderr = shell-init: only. After:
    shell-init: + one chdir: line, byte-identical to GNU for
    dot/dot2/dotdot; the pwd form already matched and still does.
    Form A probes (d01–d06) unchanged.
  • Fail-first: the three new chdir cells fail on base src with
    exactly the missing line; all five cells pass after the fix.
  • cargo test --lib: 1341 passed, 0 failed.
  • Local pin-stem census differential (macOS back-to-back,
    base 60ed70e5 12310 tests vs fixed 12319): both sides carry
    the same 663-name local-environment failure background; the
    symmetric difference is 8 names, all in known rotation families
    (issue3949 coproc members on both sides, coproc-family
    issue387/issue1632, issue2771, issue1631, issue2972), none in
    the change surface; 0 signal-terminated tests on either side.
    (The change is the identity for every non-empty startup value,
    so healthy-shell behaviour cannot move.)

Not in this PR

The $PWD value bound by a relative cd from the poisoned state
(GNU binds the spelled . / .. against the NULL base; rubash
binds a resolved destination — visible in the d06 /. face and
the form-B dotdot pwd output) is the separate PWD-value
residual already recorded with rubash#3574's cells. Diagnostics
only here, per the issue's acceptance.

…e chdir line

A shell born in a deleted cwd seeded its logical cwd as Some(""):
the empty adoption was stored as a live value. GNU keeps tcwd NULL
in that state, and the cd entry re-derivation gate
(get_working_directory "chdir", cd.def:529-534) is exactly
logical_cwd.is_none() -- mid-session poisoning (#3574) uses None and
prints the chdir: line, birth poisoning used Some("") and never did.
Both seeding points (Executor::new, in-process subshell seeding) now
store None for an empty adoption, sharing the single poisoned-state
representation. Healthy shells are unaffected (non-empty values are
identical). Adds 5 pins; fail-first verified on base.

Refs #4120 (not Fixes).
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