Repository navigation
fix(executor): coproc honors here-string/heredoc stdin redirects (rubash#1651) - #1694
Merged
Merged
Conversation
…ash#1651)
GNU redir.c do_redirections binds fd 0 to the redirect
before the coproc child runs, so the coproc consumes the
body and exits. Rubash's apply_coproc_redirects only
handled the single-field redirects (redirect_in/out/
append/err), and a memory-backed body never lands in
redirect_in — a here-string lives in cmd.redirects +
cmd.here_string, a heredoc in cmd.redirects +
cmd.heredoc_redirects — so the child stayed on the coproc
pipe and 'coproc cat <<< hi' blocked forever (while
'< file' worked).
The fix resolves the winning fd-0 body (same last-wins
ordering as stdin_string_for_command_mut, whose
here-string expansion also strips quotes segment-wise —
the read-only fallback left them, feeding '"hello"'
with quotes) and feeds it to the child through a
pre-filled pipe (writer thread, so a body larger than
the pipe buffer cannot block the spawn; the parent's
coproc write end stays registered as ${COPROC[1]},
useless but present, like GNU's rebound pipe end). Only
HereDoc/HereString winners take this path: '< file'
keeps the real-file path, and '<&N' dups keep the pipe
(streaming a dup through a string buffer would change
blocking behavior).
Regression tests:
tests/issue1651_coproc_heredoc_stdin_regressions.rs (10 tests:
herestring/heredoc consumed + exit, content + expansion +
quotes, file control, last-wins both directions, compound
body, 500-line heredoc, numbered/empty herestring).
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.
Fixes #1651.
GNU redir.c do_redirections binds fd 0 to the redirect before the coproc child runs, so the coproc consumes the body and exits. Rubash's apply_coproc_redirects only handled the single-field redirects (redirect_in/out/append/err), and a memory-backed body never lands in redirect_in — a here-string lives in cmd.redirects + cmd.here_string, a heredoc in cmd.redirects + cmd.heredoc_redirects — so the child stayed on the coproc pipe and
coproc cat <<< hiblocked forever (while< fileworked).The fix resolves the winning fd-0 body (same last-wins ordering as stdin_string_for_command_mut, whose here-string expansion also strips quotes segment-wise — the read-only fallback left them, feeding
"hello"with quotes) and feeds it to the child through a pre-filled pipe (writer thread, so a body larger than the pipe buffer cannot block the spawn; the parent's coproc write end stays registered as ${COPROC[1]}, useless but present, like GNU's rebound pipe end). Only HereDoc/HereString winners take this path:< filekeeps the real-file path, and<&Ndups keep the pipe (streaming a dup through a string buffer would change blocking behavior).Verification (local, master 499a5e2 + this fix, vs GNU bash 5.3.20):
coproc cat <<< "hello"/ heredoc form: child exits on its own (DEAD, wait_rc 0) instead of blocking; content, quoting, and variable expansion all match GNU; compound body + herestring works; last fd-0 redirect wins in both directions; 500-line and 200KB heredocs transfer without deadlock.Known pre-existing divergence, unchanged here and unrelated to this issue: reading a coproc fd inside a pipeline stage (
cat <&${COPROC[0]} | wc -l) yields 0 lines on rubash (master included) while GNU reports 'Bad file descriptor' — pipeline-stage coproc-fd handling needs its own issue.