Skip to content

executor: a session born in a deleted cwd keeps its inode instead of a fabricated / - #3298

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix-3268-e-birth-anchor
Nov 10, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix-3268-e-birth-anchor

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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 /: pwd printed / with status 0, $PWD was seeded /, children were stamped into /, and ls .. 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 and same_file(PWD, ".") holds; otherwise get_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:

  • The birth cwd is captured once in Executor::new and feeds both the env seed and the ShellState field (they previously called current_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.
  • On capture failure the field takes the empty path — the honest unknown, which never resolves and never equals a real directory — and the birth anchor is opened on . (which succeeds on a deleted directory) naming the field. stamp_spawn_cwd then fchdirs spawned children into the real inode and read_session_anchored openats operands from it, until the first successful cd replaces field and anchor.
  • PWD is not seeded in the unknown state (set_pwd parity: neither rebound nor empty-seeded; an imported PWD keeps its stale value, an absent one stays unbound), and a fresh birth prints the shell-init: line once. Respawned children stay silent — a fork child never re-runs startup — and the per-command job-working-directory: repeats are deliberately not reproduced.
  • pwd with the unknown cwd now fails like GNU's: nothing on stdout, the pwd: line on stderr, status 1.
  • E6 respawn births: the whitelisted spawn used to leave an unresolvable session cwd unstamped, so an async child was born in the host process's cwd and believed it. WhitelistedSpawn now carries the session's anchor fd and the spawner fchdirs the child into the inode, the same landing stamp_spawn_cwd gives 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 inherited the_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

  • The two unwrap_or_else(|_| PathBuf::from("/")) birth fallbacks in Executor::new (env seed and ShellState literal) — the fabrication itself.
  • The unconditional PWD insert in initialize_fresh_shell_env_vars (now conditional on a known cwd).
  • The stale spawn_whitelisted comment 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_path consumer 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.

…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
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