Repository navigation
WIP: fix(executor): coproc honors dup output redirects like >&2 (transplant of #1695) - #1985
Merged
Merged
Conversation
…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]>
caomengxuan666
marked this pull request as ready for review
October 28, 2026 15:47
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
移植自 PR #1695(a-rookie-of-C-language)
本 PR 是 #1695 的实现向当前 master 的移植合入,依 coproc 线终裁执行(裁定证据:coproc 裁定簇 REPORT §四专审;裁定记录 DECISIONS.md「coproc 线终裁」)。
1bcffe8e,2026-10-26 05:06 +0800),早于我方 fix7 coproc-life: coproc lifecycle & grammar fixes (12 issues) #1712(2026-10-26 01:18 UTC 创建)——对方在先。为何移植而非原样点合:#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