Repository navigation
fix(executor): warm the cwd anchor when pushd/popd move the session cwd - #3384
Conversation
After pushd into a deleted cwd, external children ran in the startup cwd instead of inheriting the deleted cwd. Root cause: rubash never chdirs the process (G-02 model), so a child can only land in a deleted inode via an anchor fd fchdir (stamp_spawn_cwd). execute_cd warmed the anchor after every move, but the pushd/popd funnel never did, so the spawn stamp found no anchor naming the current cwd and let the child through unstamped, inheriting the process cwd (= startup cwd). The fix, in execute_stack_builtin (the single pushd/popd/dirs funnel, trap_stack_builtins.rs, +24 lines, no deletions): compare the session cwd before and after execution and refresh_cwd_anchor() when it moved — the same call execute_cd uses. The gate is 'cwd moved', not status==0: a readonly-bind failure still moves the chdir (pushd.rs G-02 note), while pushd -n / dirs do not move and need no refresh. GNU pushd's Dir operand delegates to cd_builtin (pushd.def:298; rotation via change_to_temp -> cd_to_string -> cd_builtin, :265/:284/:576-586/:562-574; popd top via cd_to_string, :400); change_to_directory chdirs the process cwd (cd.def:600); execute_disk_command forks via make_child and the child inherits the shell's cwd (execute_cmd.c:5771). Refs unixwin#3336 Regression pin tests/issue3336_pushd_deleted_cwd_spawn.rs (7 tests; fail-first 1 passed / 6 failed on the unpatched tree, 7/7 pass after; supervisor verified both rounds with the patch method). The issue's seed script seed_r88e2.sh: GNU 5/5 PASS, rubash 5/5 PASS after the fix. Adjacent: 20 files, 166 items green (issue3198 7/7, unixwin#3275 4/4, unixwin#3268 four files 12/12+9/9+10/10+19/19, dirstack/pushd family incl. unixwin#2424 21/21 — supervisor re-ran issue3198 and unixwin#2424). cargo fmt clean.
|
Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge, and #3336 stays open until that review lands. CI at intake: all 10 checks green (1 skipping). First pass: one funnel function, +24 lines, pin 7/7 fail-first (1 passed / 6 failed on the unpatched tree), plus 166 adjacent items green. Two things noted for the captain: your Owed items (background-spawn face, readonly-PWD stale cwd) are flagged as separate issues, and #3386 touches the same |
Captain review — PASS (merge conditions below)Joint review with PR #3386 (same funnel, one dossier: Declaration reconciliation — every claim checks out
One correction to the merge note in the companion PR: the two stack-funnel changes do not auto-merge — a trial merge conflicts in Owed items — captain delimitation (evidence in the dossier)
Merge conditions: final head CI finished all-green (the current head already is); if this PR merges second, the union protocol above applies. |
Fixes #3336
What was fixed
After
pushdinto a deleted cwd, external children ran in the startup cwd instead of inheriting the deleted cwd.Root cause: rubash never chdirs the process (G-02 model), so a child can only land in a deleted inode via an anchor fd
fchdir(stamp_spawn_cwd).execute_cdwarms the cwd anchor after every move, but the pushd/popd funnel never did — so after a pushd move the spawn stamp found no anchor naming the current cwd and let the child through unstamped, inheriting the process cwd (= startup cwd).The fix is in
execute_stack_builtin(the single pushd/popd/dirs funnel,src/executor/trap_stack_builtins.rs, +24 lines, no deletions): compare the session cwd before and after execution and callrefresh_cwd_anchor()when it moved — the same callexecute_cduses. The gate is "cwd moved", notstatus == 0: a readonly-bind failure still moves the chdir (pushd.rs G-02 note), whilepushd -n/dirsdo not move and need no refresh. This covers pushd entry, popd top,pushd +1rotation, and barepushdswap in one place.GNU: pushd's Dir operand delegates to
cd_builtin(builtins/pushd.def:298; rotation viachange_to_temp→cd_to_string→cd_builtin,:265/:284/:576-586/:562-574; popd top viacd_to_string,:400);change_to_directorychdirs the process cwd (builtins/cd.def:600);execute_disk_commandforks viamake_childand the child inherits the shell's cwd (execute_cmd.c:5771) — a deleted directory is still the child's cwd, withgetcwdfailing.What was deleted
Nothing. No files, features, or tests were removed.
Verification (all run, per-item counts)
tests/issue3336_pushd_deleted_cwd_spawn.rs: 7/7 pass (pushd entry, popd top,pushd +1rotation, barepushdswap, pipeline stage,sh -cchild reporting getcwd failure, cd-entry control). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 1 passed / 6 failed — only the cd control passed; all 6 pushd faces were red, with children listing the startup cwd. Expectations are all from GNU 5.3.20 oracle measurements.seed_r88e2.sh: GNU 5/5 PASS, rubash 5/5 PASS after the fix, rc 0.issue3198_deleted_cwd_spawn7/7, 删后原地重建目录的幽灵穿越:静止会话经复活路径读到新目录内容(GNU 仍坐死 inode 报 ENOENT) #3275 ghost 4/4, 已删 cwd 下进程内路径串解析同族残差:comsub 内 cat、cd ..、壳侧输入重定向、模拟 cp 操作数面 #3268 four files 12/12 + 9/9 + 10/10 + 19/19, dirstack/pushd family [bug] pushd 建栈后 cd 不更新 DIRSTACK[0](dirs 栈顶仍为旧 cwd) #2391 6/6, [bug] DIRSTACK[0]= 赋值未按 GNU 忽略(set_dirstack_element 索引 0 为 no-op) #2407 3/3, [bug] 伪造 $PWD 后 DIRSTACK 顶跟随变量而非物理 cwd(GNU 经 get_working_directory 校验 $PWD) #2408 4/4, [bug] DIRSTACK compound assignment via declare/local (and tempenv) bypasses the stack door — split-brain persists #2424 21/21, [bug] DIRSTACK element assignment: negative subscripts never resolve against the live stack; bad-subscript diagnostic swallowed #2432 5/5, [bug] unset DIRSTACK: braced read faces (/home/hatch, count) ignore the unset and resurrect the old stack #2434 5/5, declare DIRSTACK[name]=x: bad-subscript diagnostic prints the evaluated value instead of the written subscript #2454 5/5, [bug] pushd 对非法 -<字母> 首参与目录参数报 too many arguments(GNU:invalid number + usage,rc 2) #2820 5/5, pushd 不查 CDPATH(cd 同形正常) #3196 6/6, pushd // 被归一化成 /(dirs 顶与 PWD 均错) #3197 3/3, [bug] cd 对软链父目录的..按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796 12/12, cd inside un-redirected command substitution resolves against startup cwd after the shell has cd'd #2211 14/14, comsub 里字面空操作数 cd 静默跳 HOME(GNU 报 null directory) #2219 9/9, [bug] 交互 shell 的 autocd 不生效(目录名命令未转 cd) #2396 7/7 — supervisor re-ran issue3198 and [bug] DIRSTACK compound assignment via declare/local (and tempenv) bypasses the stack door — split-brain persists #2424).cargo build -j 2clean,cargo fmt --checkclean.src/lexer/continuation.rsuntouched.Owed
spawn_async_direct→raw_fork_async_child(external_inner.rs:5605) chdirs by path string and never consults the anchor — a backgroundlsin a deleted cwd reportschdir: …: No such file or directory, rc 1, and this is broken aftercdtoo (baseline measurement), so it is an independent [bug] kill -INT does not kill a non-monitor async job; GNU wait returns 130 #2925 async-spawn defect, not a [bug] after pushd into a deleted cwd, external children run in the startup cwd instead of inheriting the deleted cwd #3336 residual. Fix would be to pass the anchor fd into the raw-fork child as an fchdir fallback. A background case was in this pin originally and was removed because it was a false pass on the baseline (ls never ran, output was empty)...按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796 family, needs a separate issue): afterreadonly PWD; cd a, a subshell's logicalcd ..resolves against the stale $PWD (lands in /tmp); GNU resolves against the chdir-updatedthe_current_working_directory(lands in $D). Confirmed by baseline vs GNU measurement; out of this issue's scope.