Skip to content

fix(fd,executor): relocate cwd anchor out of low fd range with move_to_high_fd (#3640) - #3891

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3640-startup-cwd-fd3
Nov 18, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3640-startup-cwd-fd3

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3640

Summary

  • Add move_to_high_fd and move_file_to_high_fd in src/fd/unix.rs (scanning down from min(sysconf(_SC_OPEN_MAX), 256) - 1 to 4 with FD_CLOEXEC re-armed, matching GNU general.c:702).
  • Apply move_file_to_high_fd at both CwdAnchor open sites (src/executor/init.rs birth capture and src/executor/external_inner.rs
    efresh_cwd_anchor_for) so the session cwd anchor no longer occupies fd 3 and exec 3>file lands on fd 3.
  • Add ests/issue3640_startup_cwd_fd3.rs covering startup fd 3, exec 3>file, exec 4>file,
    ead -u 3, child writes via >&3, high-fd cwd anchor placement, and deleted-cwd spawn survival.

Verification

ustfmt --edition 2021 --check on all touched files: passed

  • WSL cargo test --locked --test issue3640_startup_cwd_fd3: 7 passed, 0 failed
  • WSL cargo test --locked --test issue3198_deleted_cwd_spawn --test issue3286_deleted_cwd_fifo_redirect --test issue3286_deleted_cwd_fifo_redirect_regressions: 7 + 3 + 11 = 21 passed, 0 failed

@caomengxuan666
caomengxuan666 merged commit 2941350 into master Nov 18, 2026
7 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3640-startup-cwd-fd3 branch November 18, 2026 10:04
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] Shell holds its startup cwd open on fd 3, so exec 3>file lands on fd 4

1 participant