Skip to content

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

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3363-absorb-deleted-cwd-fifo
Nov 18, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3363-absorb-deleted-cwd-fifo

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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 删除了什么

UNVERIFIED-BY-CAPTAIN

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

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3867 第1轮(m1 审计)— 建议:FAIL
head: e9e513c base(merge-base): 见 gh 实时值 文件: 2 个(src/executor/trap_exec.rs + tests/issue3286_deleted_cwd_fifo_redirect.rs)
关联 issue: #3286(deleted-cwd FIFO redirect 面)

机制核查:

  • GNU redir.c:237 do_redirections 逐条 redir → redir.c:725 redir_open 单次 open;输出/追加 flag 见 make_cmd.c:669-674(O_TRUNC|O_WRONLY|O_CREAT / O_APPEND|O_WRONLY|O_CREAT)。fix(redirect): open output/append FIFO redirects via cwd anchor in bind phase (Refs #3286) #3735 已把普通输出/追加 FIFO bind 走 cwd anchor;本 PR 把同一不变量扩到 exec 面:set_fd_output_file 对相对操作数经 open_via_cwd_anchor,exec_spawn_open_output 追加走 open_append_target_for——机制方向与 GNU 一致,未发现顺手无关改动。
  • 但本 PR 自带钉在 head 上有 1/3 红,且红的根因不在本 PR 的 redirect 机制。

腿:

  • 钉自跑:issue3286_deleted_cwd_fifo_redirect 2 passed / 1 failed。过:bare exec > ../fifo、bare exec >> ../fifo(cwd-anchor 打开生效)。红:issue3286_exec_command_append_redirect_to_existing_fifo_from_deleted_cwd——stderr /usr/bin/echo: cannot execute: required file not found,exit 127,FIFO 无数据。
  • 根因归属:该形状是 exec <cmd> >> fifo 的替换执行路径——redirect 打开本身已由本 PR 修好,但随后的外部命令解析/映像替换在已删 cwd 下仍按路径重解析(src/builtins/exec.rs:1038 replace_process_image → process.current_dir(cwd) 对失效路径;stamp_spawn_cwd external_inner.rs:2603+ 的既有基建未覆盖 exec 映像替换)。这是 已删 cwd 下前台外部命令 spawn 全部 rc 127(spawn 按陈旧逻辑 cwd chdir) #3198「deleted session cwd 外部 spawn」的独立缺口,非本 PR diff 引入。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20 patch20,同脚本文件对照——GNU exec echo hello >> ../fifo(deleted cwd)成功、FIFO 收到 hello;rubash head 127。redirect-open 语义本身两侧一致,分歧只在命令执行腿。
  • fail-first / lib 双边 / -D warnings / 卫生 / CI:未跑全量——判词已由钉红定案,列为未跑腿。

F 点:

未跑/VOID 的腿:fail-first、lib 双边、-D warnings、marker/utf8 卫生、CI 逐项核查(判词已定,未展开)。

…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.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:29
@caomengxuan666
caomengxuan666 merged commit 93a56df into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3363-absorb-deleted-cwd-fifo branch November 18, 2026 08:29
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