Repository navigation
fix(executor): pass process-substitution fds to external command arguments on Unix - #468
Merged
Merged
Conversation
…ments on Unix (fixes #438)
This was referenced Oct 9, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…483) GNU folds `word<(` into the word via read_token's fall-through (parse.y:3793-3797) and read_token_word's shellexp arm (parse.y:5494-5524), with the `(...)` body consumed under parse_matched_pair's LEX_GTLT discipline (parse.y:4147-4153) where newlines are ordinary body characters. rubash's word scanner already spans the body (skip_cmd_subst), but the tokenizer's logical-line join gate had no signal for it, so `echo outer<(` NL `echo inner` NL `)` — and the h4l/json.bash jb-cli `jb menu:json@<(...)' nesting example — died with `syntax error near unexpected token `)'`. - word_ends_in_open_process_substitution (continuation.rs): quote/ escape/backtick-aware scan of the last word token's raw span; answers whether the word ended inside an unclosed word-attached `<(`/`>(`. - GroupScanFeeder join gate (lexer/mod.rs): when the pass's last token is that word, hold the logical line open for the next physical line, clear the tail-resume checkpoint (the pass ended mid-word), and let token_level_needs_more report it so the incremental group reader (script/`-c` execution) keeps appending too. - Bare `<(` (word-initial) is untouched — the parser's own procsub bridge handles it; #424's extglob redirect rejections stay green; #339/#355/#468 procsub suites pass. Oracle: GNU bash 5.2.37 msys (D:\Git\usr\bin\bash.exe) — rc=0 on every accepted shape, byte-identical stdout on executed shapes. Known out-of-scope gap, pre-existing on master: interactive/stdin-source completeness (stdin_source_text_needs_more) and the `-c` space-form body still lack their own arms; truncated-EOF diagnostics unchanged. Tests: tests/issue463_multiline_procsub_word_regressions.rs (9 cases: minimal repro, line-spanning continue, jb-cli nesting, output procsub, comsub-wrapped, single-line forms, #424 rejections, quoted opener). src/executor/path.rs is cargo fmt reformat of pre-existing test code. Closes #463
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.
Fix external commands receiving a process substitution as an argument on
Unix: the literal
/dev/fd/Nargv word now resolves in the child, as inGNU bash.
Problem (#438)
GNU forks before exec'ing an external command, so the child inherits the
shell's descriptors and resolves
/dev/fd/Nthrough the OS /dev/fd layer(execute_cmd.c passes argv to execve unchanged; the live pipe read end at
descriptor N is the whole contract — subst.c:6362 process_substitute ->
move_to_high_fd -> make_dev_fd_filename). rubash's virtual fd table is not
the child's descriptor table: the substitution's buffered endpoint had no
real descriptor, so the child's
open("/dev/fd/N")failed ENOENT. Onlythe procsub-as-argument path was broken (
cat < <(...),mapfile < <(...)already worked).
Fix
materialize_dev_fd_operands(src/executor/dev_fd_operands.rs): onUnix, a
/dev/fd/Noperand naming a buffered virtual read endpoint(
Text/ProcessSubstitution) is now backed with a real anonymous pipecarrying the endpoint's remaining bytes (fed from a writer thread so a
payload larger than the kernel pipe buffer cannot deadlock the shell).
The argv word itself stays literal
/dev/fd/N, as in GNU. File-backedendpoints keep the literal word (the OS resolves it natively).
attach_unix_dev_fd_operands: apre_exechook (dup2, async-signal-safe) pins each recorded read end at its
/dev/fd/Nnumber in the childbetween fork and exec; it also clears FD_CLOEXEC when the fresh pipe fd
landed on the target number itself (dup2(fd, fd) does not). The parent
closes its copies when the materialization record drops, matching GNU's
post-fork close unwind.
spawn_external_process(simple commands), the sequential pipelinestage executor, and both command-substitution external spawns.
On Windows nothing changes: the documented platform contract remains
temp-file materialization of the virtual endpoint (rubash#355 residuals).
Residuals (documented, out of scope)
exec diff <(a) <(b)(theexecbuiltin's own spawn helpers inbuiltins::exec) does not yet attach the pipes; same behavior as before.
>(cmd)as an external argument keeps its previous behavior.Tests
tests/issue438_procsub_fd_arg_regressions.rs(black-box,CARGO_BIN_EXE_rubash,#[cfg(unix)]): external arg read, pipelinestage, the issue's
diffreproducer (equal and differing inputs),independent streams, >64 KiB payload (writer-thread path), procsub arg
inside
$(...), and the argv word staying/dev/fd/N(no temp-pathrewrite on Unix).
issue355_procsub_dev_fd_form_regressions(incl. its externaldiff/wccases) green.Oracle note
WSL was unavailable in the fix environment, so behavior was contrasted
against Git for Windows' real GNU bash 5.2.37 (msys build); #438 is the
classic fork/exec
/dev/fdinheritance contract, not a 5.3 feature, so5.2 is a valid reference. (The msys child itself cannot reopen a foreign
/proc fd on Windows, so the oracle comparison there is limited to word
forms; the byte contracts in the new tests are the longstanding GNU
semantics.)
Closes #438