Repository navigation
fix(redirect): open output/append FIFO redirects via cwd anchor in bind phase (Refs #3286) - #3735
Conversation
…nd phase (Refs #3286) From a deleted cwd, a relative output/append redirect to an existing FIFO failed instantly with ENOENT: the anchor carve-out (#3268) classified the FIFO out of the anchor open and fell back to the joined string path, which dies at the dead component. GNU opens the target once, in the child (redir.c:237), so the write open blocks for the reader rendezvous and then succeeds. Split the two phases: the bind opens (create_redirect_output, open_append_target) take the anchor O_WRONLY openat for a FIFO, while the probe faces (setup-walk probes, compound prepared phase, #1868 validation walk) validate a FIFO by anchor faccessat and never open it (#1820). The background guard (#1862) and procsub plan-capture guard still defer the FIFO open to the child, and the empty-stream pairing open goes through the anchor-aware append opener. Regression tests: tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs (11 pins: reader/no-reader cells for > and >>, compound-inner echo, empty-stream pairing via echo -n, live-cwd/external/regular-file neighbors, missing-target control, background-job non-blocking).
|
Thanks for the PR — intake has read the full diff and checked CI, and this is queued for captain review. A few verified notes first: CI, checked by name (not just red/green): the three failing Rust-test legs (GNU goldens, Rust tests, Rust tests macOS) all fail on exactly one cell, First-pass read of the mechanism (from the diff, not yet run): the two-phase split is coherent with the stated GNU anchor (redir.c:237, single open in the child) and the #1820 discipline — bind faces ( Sequencing — please read: #3286 already has an earlier open PR, #3363 by Uarz (opened 2026-11-11, draft, One small hygiene ask: the body has no "What was deleted" section — please add a line confirming nothing was deleted (or list it), so the merge checklist is complete. Nothing is merged from intake, and no changes are requested beyond the note above. Thanks again for the careful GNU-oracle evidence in the body. |
|
【WIN-AGENT-AUDIT】PR #3735 第2轮 — 建议:PENDING(缺腿已补;排序仍待队长裁) 本轮补齐上一轮缺的 Linux 原生腿(fd/FIFO 语义 Windows 仿真不可信,规程要求 WSL 原生构建复核)。环境:WSL 机制核查(维持第1轮结论,补 GNU 引用):
腿(逐项数字与名字):
F 点:无(本轮未发现新问题;机制与 GNU 语义一致) 续作记录:无(未动代码、未 push) 未跑/VOID 的腿:
|
…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]>
Root cause
From a deleted cwd, a relative output (
>) / append (>>) redirect to an existing FIFO failed instantly with ENOENT, while GNU bash 5.3.20 blocks for the reader rendezvous and then succeeds (or blocks with no reader).The anchor carve-out (#3268) classified an existing FIFO out of the anchor open and fell back to the joined string path (
File::create(path)), which dies at the dead component under a deleted cwd. The carve-out rationale is real — an anchorO_WRONLYopen in the probe phase would consume/block the bind's rendezvous (#1820 discipline) — but it turned a GNU success into an instant failure.Fix
Two-phase split:
create_redirect_output,open_append_target) take the anchorO_WRONLYopenat for a FIFO — the single open GNU does in the child (redir.c:237).faccessatand never open it.Evidence (fixed binary vs GNU 5.3.20)
echo hello > ../fifo: rubash rc=0, reader gothello(baseline: instant../fifo: No such file or directory, rc=1).>>and compound-inner echo: identical to GNU with a holding reader (rc=0, reader got bytes).echo -n "" > ../fifopairs (EOF) like GNU; external/bin/echoandprintfneighbors identical.echo bg > ../fifo &does not block the parent (spawn rc=0, parent survives).Verification
tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs: 11/11 pass.cargo test --lib: 1249 passed, 0 failed.> f1 > f2never creates/truncates f1 — bash creates both (empty f1) #1392 (2), 已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功) #3286 (11).cargo fmt --check,git diff --checkclean.Notes (out of scope, pre-existing)
{ echo world; } > ../g2, regular file) under a deleted cwd still fails on baseline — a separate, wider gap, not touched.printf ""renders zero output chunks and never reaches the flush, so it does not pair a FIFO even on a live cwd — a pre-existing live-cwd gap, not this issue's cell; the test pinsecho -n ""instead.Refs #3286