Repository navigation
executor: port GNU async-stdin verdict to pipe-fed pipeline elements - #3734
Conversation
Refs #3605 exec13.sub's pipe-fed compound elements (`echo x | ( cat & wait )`, `| { cat & wait; }`, function elements) lost their lines: the async child spawned with /dev/null stdin because the element clone never inherited the "my stdin is a pipe" verdict. GNU anchors (bash-5.3 vendored tree): - execute_cmd.c:4570 — the forked element child does `stdin_redir |= (pipe_in != NO_PIPE)`; a pipe-connected element's async spawns read the pipe, not /dev/null. - execute_cmd.c:1733 — `execute_subshell_command` ASSIGNS `stdin_redir = (own fd-0 redirects) || (pipe_in != NO_PIPE)`; a nested `( )` clears an enclosing verdict, and the element's own `< file` replaces the pipe via do_redirections. - execute_cmd.c:1759-1764 — the :826 `stdin_redir = redirects` assign for shell control structures runs AFTER do_redirections consumed the element's fd-0 redirect, so it must not re-set the flag. - eval.c:181 — only reader_loop clears stdin_redir between commands; evalstring.c's parse_and_execute does not, so a clone replaying a pre-parsed element list must not clear either. - jobs.c:1743/nojobs.c child_setup — the async child consults the verdict when picking /dev/null vs inherited fd 0. Port: - `execute_pipeline_stage` gains a `stdin_is_pipe` parameter; the stage entry ORs it into `shell_state.stdin_redir` and the epilogue restores the caller's flag. Real-OS-pipe stage call sites (loop stages index > 0, streaming tail/mid) pass true; producer/stage-0 and the timed-read followup pass false. GNU's lastpipe quirk (prev = NO_PIPE before dispatching the last element) means the lastpipe path needs no marker. - New one-shot `element_pipe_stdin` Cell on ShellState: set on the compound-stage clone, consumed at the clone's own compound dispatch — the `( )` :1733-style assign (`own fd-0 redirects || marker`) and the :826-style assigns in `command_execute`/`execute_brace_group_pipeline`, both of which GNU skips for pipe-connected elements. - ast_exec's per-command reader-loop clear now only fires at subshell_depth == 0 (eval.c:181); a stage clone's body walk is not a reader loop. - `bind_command_fd0_input` drops the FUNCTION_STDIN(+OFFSET) mirror after binding a real fd-0 endpoint (file, procsub, net): GNU's do_redirections replaces fd 0 wholesale, so a stale pipe mirror must not shadow the bound file for `inherited_async_stdin`. Verification vs GNU bash 5.3.20 (script files, byte-identical stdout/stderr/rc): exec13.sub shapes x1/x1a/x2b/x3/x3a incl. GNU's empty x2/x2a, x3b + lastpipe forms, and a 13-form probe matrix (pipe-fed `( )`/`{ }`/if/while/for/case/select/coproc elements, element-own-`< file` override, nested-clear assign semantics, stage-scoped flag death). niubash gate slice run-execscript: the x1..x3b family now matches exec.right; remaining diffs are the already-tracked E2BIG/#3712, exec -a prolog, coproc and job-control noise. tests/issue3605_pipeline_async_stdin.rs pins the four shapes (4 tests). Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Dedup note from a parallel exec13 session (built + matrix-verified this branch's head Extra cases verified on this branch that the current pin file doesn't cover, if you want them as added pins:
No action needed — the family is owned here; #3755 dropped its duplicate and carries only the unrelated |
|
【WIN-AGENT-AUDIT】PR #3734 第1轮 — 建议:PASS 机制核查:
腿:
F 点:无。 续作记录:
未跑/VOID 的腿:CI 全腿(run pending);lib 双边仅 Windows 侧(Linux lib 未跑,fd/管道语义差异风险低但注明)。 |
Summary
Refs #3605 — exec13.sub's pipe-fed compound elements (
echo x | ( cat & wait ),| { cat & wait; }, function elements) lost their piped lines: the element's asynccat &spawned with/dev/nullstdin because the element clone never inherited the "my stdin is a pipe" verdict. Upstream gaterun-execscriptshows thex1..x3bfamily blank; the GNU golden expects all eight lines.GNU anchors (vendored bash-5.3 tree):
execute_cmd.c:4570— the forked element child ORs the verdict:stdin_redir |= (pipe_in != NO_PIPE).execute_cmd.c:1733—execute_subshell_commandASSIGNSstdin_redir = (own fd-0 redirects) || (pipe_in != NO_PIPE); a nested( )clears an enclosing verdict and the element's own< filereplaces the pipe viado_redirections.execute_cmd.c:1759-1764— the:826assign for control structures runs afterdo_redirectionsconsumed the element's fd-0 redirect, so it must not re-set the flag.eval.c:181— onlyreader_loopclearsstdin_redirbetween commands;evalstring.c'sparse_and_executedoes not.Port
execute_pipeline_stagegains astdin_is_pipeparameter; the stage entry ORs it intoshell_state.stdin_redirand the epilogue restores it. Real-OS-pipe stage call sites passtrue; producer/stage-0 and the timed-read followup passfalse. GNU's lastpipe quirk (prev = NO_PIPEbefore dispatching the last element) means the lastpipe path needs no marker — verified:shopt -s lastpipe; echo x9 | ( cat & wait )prints nothing.element_pipe_stdinmarker (Cell<bool>onShellState): set on the compound-stage clone, consumed at the clone's own compound dispatch — the( ):1733 assign (own redirects || marker) and the :826 assigns incommand_execute/execute_brace_group_pipeline, which GNU skips for pipe-connected elements.ast_exec's per-command reader-loop clear now only fires atsubshell_depth == 0(eval.c:181); a stage clone's body walk is not a reader loop.bind_command_fd0_inputdrops theFUNCTION_STDIN(+_OFFSET) mirror after binding a real fd-0 endpoint (file / procsub / net): GNU'sdo_redirectionsreplaces fd 0 wholesale, so a stale pipe mirror must not shadow the bound file forinherited_async_stdin.Verification
( )/{ }/if/while/for/case/select/coproc elements, element-own-< fileoverride, nested-clear assign semantics, stage-scoped flag death.run-execscript: thex1..x3bfamily now matchesexec.right. Remaining diffs are the already-tracked E2BIG (fix(executor): report E2BIG wording for an oversize command line (Refs unixwin/niubash#993 S4) #3712),exec -aprolog, coproc and job-control noise.tests/issue3605_pipeline_async_stdin.rspins the four shapes (4 tests, all green); stdin/lastpipe regression slice green (6 files).