Skip to content

fix(executor): open existing FIFO redirect targets via the cwd anchor in a deleted cwd - #3363

Closed
Uarz wants to merge 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3286
Closed

Uarz wants to merge 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3286

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #3286

What was fixed

In a deleted cwd, a relative output redirect to an existing FIFO failed instantly with ENOENT. The probe faces classified FIFO targets by joined-path metadata, which a dead cwd defeats. GNU opens the FIFO once in the child and blocks on the rendezvous until a reader arrives.

The fix removes the FIFO gates from create_redirect_output (>) and open_append_target (>>) and opens once via the cwd anchor (O_WRONLY|O_CREAT|O_TRUNC / O_WRONLY|O_CREAT|O_APPEND); the four probe entries now classify by anchor fstatat plus a faccessat(W_OK) check instead of joined-path metadata. Trap-exec exec > / exec >> and compound-command binding (set_fd_output_file) go through the same anchor path.

What was deleted

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

Verification (all run, per-item counts)

Owed

  1. exec <>../fifo (read-write face) still ENOENT in a deleted cwd; GNU succeeds. Same anchor shape as set_fd_output_file, left out of scope.
  2. cd redirects fail for all relative targets in a deleted cwd (pre-existing, open_cd_redirect_file does a bare cwd.join open).
  3. write_to_fd empty-stream pairing branch still uses joined-path FIFO checks; no reproducer exists, left as analysed residue.
  4. /dev/tcp output face: plain > opens the connection twice and delivers zero bytes with a write error (output-side sibling of #1950) #1967 net counting flake: the counting server's accept loop checks stop before draining the backlog.

… in a deleted cwd

In a deleted cwd the probe faces classified FIFO targets by joined-path metadata, which a dead cwd defeats, so a relative output redirect to an existing FIFO failed instantly with ENOENT. GNU blocks on the rendezvous and succeeds. Remove the FIFO gates from the create/append faces and open once via the cwd anchor; probes classify by fstatat instead.

Refs unixwin#3286

Regression pin: tests/issue3286_deleted_cwd_fifo_redirect.rs (7 tests; fail-first the > , >> , no-reader and exec faces failed on the unpatched tree, 7/7 pass after). Adjacent families (issue1820, issue3268, issue2550) green. GNU 5.3.20 oracle agrees on all probed shapes.

Owed: exec <> FIFO read-write face still ENOENT; cd redirects fail for all relative targets in a deleted cwd; write_to_fd empty-stream pairing residual; unixwin#1967 net counting test is a pre-existing harness flake.
@caomengxuan666

Copy link
Copy Markdown
Member

Superseded by #3867 (fix/3363-absorb-deleted-cwd-fifo).

caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
…deleted cwd (Refs #3286) (#3867)

* fix(executor): open exec-face FIFO redirects via the cwd anchor in a deleted cwd (Refs #3286)

Absorbs the two trap_exec.rs residuals of PR #3363 after #3735
landed the command-attached faces: bare `exec > fifo` /
`exec >> fifo` (persistent bind) and `exec <cmd> >> fifo`
(replacement spawn) still died ENOENT from a deleted cwd.

Root cause: the redirect machine's probe/bind split classifies an
existing FIFO by anchor fstatat/faccessat and keeps no File for it,
so the bind performs the one real open — but the two exec-face binds
opened by dead joined string path instead of the cwd anchor:
`set_fd_output_file` did a plain `FileFd::open_write`, and
`exec_spawn_open_output`'s append arm did a raw
`open_redirect_append`, bypassing the registry (rubash#1964) and
the anchor.

GNU anchors (audit tree `build-gnu/bash-5.3/redir.c`): :237
`do_redirections` (one `do_redirection_internal` per entry), :790
`do_redirection_internal`, :725 `redir_open` (the single open per
redirect entry). (`redir.c:348` is inside `heredoc_expand`'s doc
comment, not the dispatcher.)

Changes (`src/executor/trap_exec.rs` only):
- `set_fd_output_file`: for a relative operand, try
  `open_via_cwd_anchor` with O_WRONLY|O_CREAT|(O_TRUNC|O_APPEND)
  first; fall back to the plain open when the anchor does not
  apply (live cwd / non-unix). For an existing FIFO this is the
  rendezvous open.
- `exec_spawn_open_output`: the append arm now calls
  `open_append_target_for(Some(redirect), target)` — the
  redirect-aware classified open whose Filesystem arm opens via
  the anchor — instead of the raw `open_redirect_append`.

Regression pins (`tests/issue3286_deleted_cwd_fifo_redirect.rs`,
unix only, 3 tests): bare `exec > ../fifo`, bare
`exec >> ../fifo`, and `exec echo hello >> ../fifo` from a deleted
cwd, each with a background reader; the command-attached faces
and the missing-target control already live in
`tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs` (#3735)
and are not duplicated here.

## 本 PR 删除了什么

- 无文件删除,无公开面删除,无行为删除。
- 唯一移除的调用点是 `exec_spawn_open_output` 追加臂里的
  `open_redirect_append(&self.session_path(...))` 原始打开,
  由等价的分类打开 `open_append_target_for` 替代(同一
  O_WRONLY|O_CREAT|O_APPEND 语义,另加分类与锚路由)。
- PR #3363 的钉 1–4、7 未随附:已由 #3735 的
  `issue3286_deleted_cwd_fifo_redirect_regressions.rs` 覆盖,
  不重复。

UNVERIFIED-BY-CAPTAIN

* fix(executor): stamp exec-spawn cwd through the session anchor (Refs #3286)

external_exec_process set current_dir(cwd) unconditionally, so an
'exec <cmd> >> fifo' replacement spawn from a deleted session cwd
failed the child's chdir with ENOENT (127 'cannot execute'). Carry
stamp_spawn_cwd's three-outcome decision on ChildFdSetup and replay
it in the exec Command builder: resolving cwd keeps current_dir, a
dead cwd the anchor names becomes the same pre_exec fchdir the
Command faces register, and a dead cwd no anchor names stays
unstamped.

---------

Co-authored-by: 曹梦轩 <[email protected]>
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.

已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功)

2 participants