Repository navigation
executor: a session born in a deleted cwd keeps its inode instead of a fabricated / - #3298
Merged
Merged
Conversation
…ed / (rubash#3268 (e))
GNU keeps no cwd string at startup: the process inode is the
state, and variables.c:907 set_pwd only seeds $PWD (trusting an
absolute imported PWD when same_file(PWD, ".") holds, else
get_working_directory("shell-init") per builtins/common.c:592,
which on failure leaves PWD unbound and prints the shell-init
line). rubash's birth path called current_dir() twice and fell
back to "/" on failure, transplanting a session born in a
deleted directory to the root directory for its whole life:
pwd printed / rc 0, children were stamped into /, relative
operands resolved against /.
Capture the birth cwd once in Executor::new. The success path is
unchanged (field = path, PWD seeded as today, anchor stays
lazy -- no new open on the respawn-hot birth path). On failure
the field takes the empty path (the honest unknown: it never
resolves and never equals a real directory), the birth anchor is
opened on "." and names the field so the two-state machinery
(stamp_spawn_cwd fchdir, read_session_anchored openat) serves
the session from the inode until the first successful cd, PWD
is not seeded, and the shell-init line is printed once. A
validated respawn whose birth getcwd fails adopts the
transported PWD as its field -- GNU's fork child inherits
the_current_working_directory verbatim (execute_cmd.c) -- and
the whitelisted spawn now fchdirs such a child into the
session's anchor inode instead of leaving it in the host
process's cwd. pwd with an unknown cwd fails with the pwd:
line and status 1 (builtins/cd.def pwd_builtin ->
builtins/common.c:592), nothing on stdout.
Regression pin: tests/issue3268_birth_deleted_cwd.rs (the
comsub-shortcut composite cell is registered #[ignore] until
face (a) merges; it is (a)'s serve, not this face's).
Refs #3268
caomengxuan666
marked this pull request as ready for review
November 10, 2026 23:14
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.
Refs #3268
The (e) birth face of the deleted-cwd family. A rubash process started by a parent sitting in an already-deleted directory inode was born believing its cwd was
/:pwdprinted/with status 0,$PWDwas seeded/, children were stamped into/, andls ..listed the root directory.Mechanism
GNU keeps no cwd string at startup — the process inode is the state, and variables.c:907
set_pwd()only seeds$PWD(an imported PWD is trusted only when absolute andsame_file(PWD, ".")holds; otherwiseget_working_directory("shell-init"), builtins/common.c:592, which on failure leaves PWD unbound). This change makes birth obey the same two-state rule as runtime:Executor::newand feeds both the env seed and the ShellState field (they previously calledcurrent_dir()independently). The success path is unchanged — field = path, PWD seeded as today, anchor stays lazy; no open was added to the respawn-hot birth path..(which succeeds on a deleted directory) naming the field.stamp_spawn_cwdthen fchdirs spawned children into the real inode andread_session_anchoredopenats operands from it, until the first successfulcdreplaces field and anchor.shell-init:line once. Respawned children stay silent — a fork child never re-runs startup — and the per-commandjob-working-directory:repeats are deliberately not reproduced.pwdwith the unknown cwd now fails like GNU's: nothing on stdout, thepwd:line on stderr, status 1.WhitelistedSpawnnow carries the session's anchor fd and the spawner fchdirs the child into the inode, the same landingstamp_spawn_cwdgives Command-based spawns (whose children were already landed correctly and were undone only by their own birth fallback). A validated respawn whose birth getcwd fails adopts the transported PWD as its field — the fork child's inheritedthe_current_working_directory— and the identity gate from the ghost face keeps the adopted string from ever counting as a resolution of it.What this change removes
unwrap_or_else(|_| PathBuf::from("/"))birth fallbacks inExecutor::new(env seed and ShellState literal) — the fabrication itself.initialize_fresh_shell_env_vars(now conditional on a known cwd).spawn_whitelistedcomment claiming a respawned child re-derives its session cwd from transported state (the transport carried no cwd; the new comment states the actual mechanism).Tests
New pin
tests/issue3268_birth_deleted_cwd.rs, 11 active cells + 1 ignored: born-dead cat/ls/pwd (unbound and stale-import shapes)/comsub/recovery/absolute-through-dead lock, respawn births from born-dead and runtime-dead parents (async and coproc arms), and a normal-birth control. Fail-first on the base tree: 8 red / 3 green (the 3 green are the parity locks) / 1 ignored; on this head all 11 active cells pass and the neighbouring stems (issue3198, issue3201, issue3275, issue2526) stay green. The ignored cell is the comsub-shortcut composite, which belongs to face (a); it is registered with#[ignore]until that face lands. (Measured on this head it passes when run explicitly — recorded in the lane report; the turn-positive decision stays with the (a) lane.)One face of five: the parent issue stays open for the remaining faces. The
session_pathconsumer census for the empty-field window is in the lane report (~/workspace/fix-3268-e/REPORT.md§5): redirect faces are the (c) face's, the simulated mkdir/rm/touch family stays with the (d) face, and the hosted (multi-session) bare-relative window is registered there per face.