Skip to content

fix(executor): carry logical_cwd in the respawn transport set - #3377

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3347
Nov 19, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3347

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #3347

What was fixed

After the parent cd'd to a real directory and forged an exported $PWD, fork-form respawn children re-derived pwd -L from the forged variable instead of the parent's logical_cwd.

The divergent face is fork-form respawn (GNU forks; rubash re-execs a new process). GNU 5.3.20 oracle measurements: pwd -L & wait, coproc bodies, and <(pwd -L) procsub bodies all printed the true value in GNU and the forged value in rubash. The ( ) / $( ) / explicit -c / script-file faces already agreed with GNU and were left alone.

The fix carries logical_cwd in the respawn transport set: the __RUBASH_LOGICAL_CWD stamp is added to the shared fork_context_transport_entries() (background, coproc, and both procsub paths all go through it — one change, four faces covered; the __RUBASH_CMD_FILE large-body script-file face rides the same env map). The respawn child adopts the transported value only on validated respawn (keep_shlvl) and only after the same_file check (logical_value_names_cwd, i.e. GNU set_pwd's identity check); otherwise it falls back to the existing $PWD derivation. Explicit -c / script-file / top-level fresh shells (keep_shlvl=false, fresh exec in GNU too) keep deriving from $PWD unchanged.

GNU: a fork child inherits the_current_working_directory as-is (builtins/common.c:589); & is execute_cmd.c:1576 execute_in_subshell, procsub is subst.c:6362 process_substitute, coproc is make_child.

What was deleted

Nothing. No files, features, or tests were removed.

Verification (all run, per-item counts)

Owed

  1. __RUBASH_CMD_FILE oversized-body (>131072 bytes) respawn script-file face: same env map and consumer as the small-body -c face, covered by mechanism but with no dedicated pin (needs a 131 KB real command; low value). Can be added if the captain asks.
  2. The 交互标记等 __RUBASH_* 内部戳记经环境泄漏给子进程(嵌套壳误判交互性) #2259 pre-existing red above — suggest a separate issue.
  3. In-process fresh shells (execute_direct_shell_script, e.g. the $THIS_SH face under virtual stdin) go through child_shell_environment(), whose PWD is overwritten with the physical cwd — a residual in the other direction from GNU's fork+reinit model, out of this issue's respawn-transport scope; whether to file is the captain's call.

After the parent cd'd to a real directory and forged an exported $PWD, fork-form respawn children re-derived pwd -L from the forged variable instead of the parent's logical_cwd. GNU forks inherit the_current_working_directory (common.c:589). The fix stamps __RUBASH_LOGICAL_CWD in the shared fork_context_transport_entries() used by background, coproc and both procsub paths, and the respawn child adopts it only on validated respawn (keep_shlvl) after the same_file check; explicit -c / script-file / top-level fresh shells keep deriving from $PWD as GNU does.

Refs unixwin#3347

Regression pin tests/issue3347_respawn_logical_cwd_transport.rs (8 tests; fail-first 5 passed / 3 failed on the unpatched tree, 8/8 pass after; supervisor verified both rounds with the patch method). Adjacent respawn/cd/pwd families green. cargo fmt clean.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 19, 2026 05:47
@caomengxuan666
caomengxuan666 merged commit e9e3d7a into unixwin:master Nov 19, 2026
10 of 12 checks passed
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.

[bug] respawn(脚本文件 spawn)在父壳伪造导出 $PWD 后从变量重派生逻辑 cwd——应随 respawn 运输集携带 logical_cwd 值

2 participants