Skip to content

WIP: pipeline/fd family — stage classification, stdin-feed race, fifo double-open, stage stderr redirect - #1841

Merged
caomengxuan666 merged 5 commits into
masterfrom
wave1/pipe-fd
Oct 27, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
wave1/pipe-fd

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Pipeline/fd 清零第一波(pipe-fd 簇)。逐条独立 commit、独立关单关键词:

Fixes #1823
Fixes #1822
Fixes #1820
Fixes #1835

另含一笔 #1720 bats 场景链的函数调用重定向 leg 分类修复(仅 Refs,不关单——链的剩余阻塞为 herestring carrier 层,见簇 REPORT):

Refs #1720

门(最终树):本族钉 1823×8 / 1822×3 / 1820×3 / 1835×6 / 1720-leg×6 + issue1605 家族钉 4 全绿;lib 773/1/1(唯一失败 ownership_unary_operators_check_existing_file,与基线全等);diffcorpus 306/306;#1822 验收同条件 100 跑零 nolink(GNU 0/40);bats 链 step 1 已过,steps 2-3/verify 剩 carrier 层(REPORT 详录)。

详细定谳与证据:簇 REPORT(随本 PR 说明交付主会话)。

…ting (rubash#1823)

A function named as a pipeline stage carrying an explicit redirect
resolved as "command not found" (127): execute_pipeline_stage_inner
checked the stage's fd-0 file redirect first and, for any name that
did not route as a builtin, jumped straight to the external spawner
without consulting the function table.

GNU routes every pipeline element through execute_command_internal
(execute_cmd.c:2620 execute_pipeline) into execute_simple_command,
which classifies the name unconditionally - find_function at
execute_cmd.c:4674-4677 - and applies the element's own redirections
inside the chosen path. Classification therefore precedes any
redirect-based routing: hoist the existing function-classification
block above the fd-0 redirect gate so function stages reach
execute_function_pipeline_stage, which applies the stage's ordered
redirects itself.

Regression: tests/issue1823_pipeline_function_redirect_regressions.rs
(8 pins, GNU 5.3.20 expectations, incl. the bats prefix-function
shape from the report).
…h#1822)

A non-final pipeline stage's external command intermittently lost
its pipe ("nolink", bogus status 1): after spawning the child, the
parent thread synchronously wrote the virtual-stdin payload into
the child's stdin pipe with `?` propagating the write error as the
command's failure. A fast-exiting child that never reads stdin
closes the read end first; the feed then hit EPIPE and the executor
discarded the child's real output and status. GNU has no post-spawn
feed - the element's fd 0 IS the pipe (execute_cmd.c:2620) - and the
two sibling feed sites (pipeline-member spawn, background spawn)
already use writer threads that swallow the error for exactly this
reason. Worse, the same unguarded feed on a non-pipeline command
let SIGPIPE kill the shell itself (exit 141).

Route all three synchronous feed sites through the new
shell_options::feed_child_stdin helper: it holds the SIGPIPE block
guard across the write and swallows only broken-pipe errors - the
child's own exit status governs. Other io errors still propagate.

Regression: tests/issue1822_stdin_feed_race_regressions.rs (seed
shape x30, status shape x20, herestring shell-survival x30).
Acceptance: 100 same-condition runs, zero nolink (GNU 0/40).
…r (rubash#1835)

A builtin pipeline stage carrying its own 2>file lost its
diagnostics entirely: the stage clone kept the stderr redirect, so
immediate-channel diagnostics were written to the file during the
stage - and the driver's route_pipeline_stage_streams then
re-applied the same redirect, its truncating setup open erasing
the bytes (the captured stderr it routed was empty). The clone
already stripped redirect_out/append for exactly this sole-owner
routing contract; redirect_err/redirect_err_append were the
asymmetry.

Strip the stderr fields plus the ordered-list fd-2 file entries
(Output/Append/ClobberOutput with fd 2, Combined forms) and fd-2
dup entries from the stage clone after the redirect preflight
(which keeps validating the unstripped list). The driver becomes
the sole applier, resolving dups in list order against the
original command - GNU applies a pipeline element's redirections
exactly once, in the element's subshell (execute_cmd.c:2620).

Regression: tests/issue1835_pipeline_stage_stderr_redirect_
regressions.rs (6 pins: ulimit/compgen seed shapes, mid/last
stage, merged >f 2>&1, 2>&1 and 2>>/function-stage non-regression).
…#1720 chain layer)

The ecosuite bats chain's setup_file markers came out empty: a
body command's own > file lost to the function CALL's > target.
apply_function_call_redirects classified the call's plain fd-1
entry as a stderr leg too - is_stderr_write_redirect defaults a
missing fd to 2, which serves the redirect_err FIELD contexts
(the field is fd-2 by construction), not ordered-list entries,
where a missing redirector defaults by direction to fd 1
(redir.c). The stderr applicator then pushed that clone into
body leaves after their own fd-1 entries, and the list-driven
buffered-output route resolved fd 1 to the call's target.

Gate the stderr leg on an explicit fd-2 claim (fd == 2, or a
combined entry whose fd-2 half the caller splits out).

Regression: tests/issue1720_function_call_redirect_leg_
regressions.rs (6 pins). Refs #1720 only: the chain's remaining
blocker is the here-string carrier layer recorded in the
pipe-fd cluster REPORT.
…1820)

Prebuilt-fifo shapes hung deterministically on both sides: each
side opened the fifo TWICE - a create/probe open (dropped unread)
and the real bind open. A blocking fifo open rendezvous-pairs, so
the probe consumed the pairing the real open needed; when both of
the writer's opens paired against the reader's still-completing
first fd, the writer wrote and vanished and the reader's second
open blocked forever. GNU opens a redirect target exactly once
(redir.c do_redirection_internal). Four layers shared the false
premise that a probe open is side-effect free, plus one double
acquisition in the text slurp:

- probe_input_redirect seam: existing FIFO -> access(R_OK) plus
  an inert /dev/null stand-in (all callers drop the File);
- setup walk Output/Append probes and create_redirect_output_
  prepared: FIFO -> access(W_OK), skip the physical create;
- reject_invalid_redirects gate Input probe and
  compound_stdin_open_failure probe: FIFO -> access(R_OK) via
  probe_input_redirect_gate (same errno surface);
- stdin_string_for_command: merge the char-device check open and
  the read_to_string open into one File::open + read_to_end.

Regression: tests/issue1820_fifo_redirect_regressions.rs (seed
shapes x5 each with a 20s watchdog, unreadable-FIFO error
surface). Case D of the narrowing variants (two independent
read commands, one writer lifetime) hangs on GNU too - faithful,
not a divergence.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 09:28
@caomengxuan666
caomengxuan666 merged commit bfda324 into master Oct 27, 2026
7 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the wave1/pipe-fd branch October 30, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment