Skip to content

WIP: fix(executor): coproc honors dup output redirects like >&2 (transplant of #1695) - #1985

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/coproc-dup-transplant-1695
Oct 28, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/coproc-dup-transplant-1695

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

移植自 PR #1695(a-rookie-of-C-language)

本 PR 是 #1695 的实现向当前 master 的移植合入,依 coproc 线终裁执行(裁定证据:coproc 裁定簇 REPORT §四专审;裁定记录 DECISIONS.md「coproc 线终裁」)。

为何移植而非原样点合:#1695 与当前 master 在 src/executor/compound_exec.rs 冲突(master 的同函数已被 #1694 的 stdin body 与 #1632 对账的移位写端交还改过形状)。本 PR 把有序循环接到现行 apply_coproc_redirects 形状上,保留 coproc_stdin_body 与 displaced-writer 两段现行语义,只换重定向施加机制。对接点与对 #1695 原文的偏离(#1632 移位写端经 spec 替换回交、#1882 stderr 计划的 fd-2 种子解析、append 臂保留 master 的 session_path 转换、自 dup 跳过为 no-op)逐条写在 commit 说明里。

测试:整取 #1695 的 7 条钉(tests/issue1644_1655_coproc_dup_stderr_regressions.rs),并吸收 #1712 的 1>&2 显式拼写钉(331c7435),共 8 条。感谢 a-rookie 的实现,也感谢 #1712 留下的拼写钉。

已知限制(如实标注,自 #1695 原样保留):dup 源 fd ≥ 3 不处理——spawn 模型不继承额外 fd,没有可忠实 dup 的目标。

Windows 面以本 PR 的 Windows CI goldens 为门(dup_coproc_process_fd 有 Windows 分支,本地只验 Linux)。

Fixes #1644
Fixes #1655

…44, #1655)

Transplant of PR #1695 (a-rookie-of-C-language, commit 1bcffe8,
2026-10-26 05:06 +0800) onto current master, per the coproc-line
adjudication: #1695's ordered state machine is the widest of the
two competing fixes (#1712's own body concedes this), passes 7/7
on its own base, and discriminates cleanly on master (all five
dup-semantics pins red, both control pins green).

GNU redir.c do_redirections runs in the forked coproc child after
the coproc pipes are dup'd, so a trailing '>&2' rebinds the child's
stdout to the shell's stderr. Rubash's spawn path only handled the
single-field file redirects and dropped every dup: a simple
command's output landed in the coproc pipe instead of the shell's
stderr (#1644), and a named group's output sat in the pipe unread
— lost entirely (#1655).

The fix applies the coproc command's output redirects to the child
in list order (GNU's left-to-right semantics, so '>file 2>&1' and
'2>&1 >file' differ as they should), replacing the field blocks —
which additionally misread '>file 2>&1' (the '2>&1' arrived as a
bogus Append field). A cloneable spec per fd makes dups copy the
current binding: '>&2' dups the shell's current fd-2 endpoint (the
#1882 direct plan's resolved endpoint, or the stderr forwarder's
target), '>&word'/'1>&word' is r_err_and_out (one open for both
fds, redir.c:832-838), '2>&word' is an ambiguous redirect
(diagnostic once, no coproc created, status 1 per the #846
coproc-failure convention), and move forms ('>&2-') close the
source in the child after the dup (self-moves excepted,
rubash#1236).

Transplant deltas vs 1bcffe8 (master moved under the PR):
- apply_coproc_redirects keeps master's rubash#1651 stdin-body /
  redirect_in head verbatim and gains the caller's stderr_forward
  target; the return becomes CoprocRedirectOutcome — Proceed
  carries the rubash#1632 displaced pipe writer, Declined is the
  ambiguous arm — so the #1632 save-slot hand-back and the #1882
  stderr plan keep their exact semantics: replacing the fd-1 spec
  hands the pipe writer back instead of dropping it, and the fd-2
  dup seed resolves from the same fd-2 endpoint the plan used.
- The append arm keeps master's session_path conversion.
- A self-dup ('1>&1', including the move spelling) is skipped as
  the no-op GNU makes it, instead of round-tripping through a
  spec clone, so the pipe writer is never displaced by a redirect
  that changes nothing.

Known limitation kept from #1695: a dup whose source is fd >= 3
is left unchanged (the spawn model inherits no extra fds).

Regression tests: tests/issue1644_1655_coproc_dup_stderr_regressions.rs
— PR #1695's seven pins taken verbatim, plus the '1>&2'
explicit-spelling pin absorbed from PR #1712 (commit 331c743).

Implementation by a-rookie-of-C-language (PR #1695), transplanted
onto current master.

Co-authored-by: a-rookie-of-C-language <[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

1 participant