Skip to content

WIP: list-level input procsub materialization (rubash#2235) - #2253

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/fd-next-2234-2235
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/fd-next-2234-2235

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Refs #2235

What

List-level INPUT process substitution on simple external commands (cat 3< <(...) <&3 and family) was never materialized: the materializer served only the fd-0 redirect_in mirror and the {var} applier, the spawn loop skipped alias-spelled targets, and the fd-0 stdin dup resolved <&N only against the ambient fd table (so the plain-file sibling cat 3<seed <&3 failed too).

GNU ground truth: do_redirections (redir.c:237) walks one ordered list; redirection_expand (redir.c:298) expands each entry at its turn; process_substitute (subst.c:6362) forks the producer at expansion.

Changes

Verification

  • New pins tests/issue2235_list_input_procsub_regressions.rs: 11 pins — 8 numbered cells red on master bbd95e3, all green with this change; 3 controls (exec / group / {var}) green on both.
  • Probe batteries (33 script-file cells vs GNU Bash 5.3.20): battery 1 byte-identical (stdout+stderr); batteries 2–3 identical except the pipeline-stage cells (cat 3<seed <&3 | wc -c family) — pipeline stage runners do not run the ordered own-list application at all; recorded as a residual for a separate pipeline-stage pass.
  • Non-regression (local, targeted, run outside the build slot): issue2195 (8/8), issue2196 (4/4), issue2200 (4/4), regression issue_1646 module (4/4). Full tests/regression.rs run (217 passed / 7 failed): 4 reds adjudicated — issue_1584/issue_1900_a4 (red on master too in this environment) and two timing-sensitive tests (issue_1951, issue_1952_bang_wait) that pass on both builds in isolation; the other 3 reds (one visible: win_face_fd_history::issue_1888_errors10_sub_verbatim) were not captured by name and are not adjudicated against master — per the compile-rationing order, that comparison belongs to the integration-side batch compile before merge. issue_1903/issue_2225 are cfg(windows) (0 local cases) — their verdict rides this PR's Windows goldens job.

Not in this PR

#2234 (chained output procsub) is design-only by brief: the live-pipe cascade design, GNU truth table, and a pins-ready draft are in the cluster report; no code, per the contained-or-design rule.

…2235)

GNU walks ONE ordered redirect list in the child (redir.c:237
do_redirections; each entry's word expanded at its own turn,
redirection_expand redir.c:298) and a <(...) word forks its
producer at expansion (subst.c:6362 process_substitute). A numbered
entry `3< <(...)` therefore binds fd 3 for every command class, and
a later `<&3` in the same list dups that binding.

Master served only the fd-0 redirect_in mirror and the {var}
applier, so on a simple external command the producer was never
spawned; the spawn loop also skipped alias-spelled targets, and the
fd-0 stdin dup resolved <&N only against the ambient fd table —
`cat 3<seed <&3` failed even for plain files.

- command_with_process_substitution_files gains the input list
  pass (the input-side sibling of #2196's output pass): every
  unserved Input/ReadWrite list position materializes like the
  redirect_in arm — stream-first to a /dev/fd/N word registered in
  the fd table, timed collection as the spawn-failure fallback.
  The field arm records its served position in both branches so
  its entry is never materialized twice, and procsub_spawn_plan
  binds a later consumer's prefix fd to the streamed endpoint.
- apply_external_stdin_redirect, on an ambient miss, replays the
  command's own list before the dup (own_numbered_input_binding):
  the last earlier binding of N wins and is opened once; the
  description is stashed in own_input_bindings and
  spawn_external_process stamps/pins that same description at N
  (GNU's dup2 shape) instead of opening the target twice. The
  spawn loop also gains the alias arm: a numbered Input/ReadWrite
  entry targeting /dev/fd/M binds M's File endpoint through the
  #1686 env/pin channels.
- The materialized alias spelling must be consumable by every
  numbered-input resolver, so the in-process binders gain the same
  alias rule (an alias target resolves through the fd table, the
  rubash#1963 layer — never a filesystem open of the spelling,
  whose real fd is an unrelated descriptor):
  open_compound_numbered_input_redirects (compounds, function
  calls, loops), read_redirected_fd (read -u N), and
  mapfile_redirected_fd_input (mapfile -u N).

Pins: tests/issue2235_list_input_procsub_regressions.rs — 8 numbered
cells red on master (external dup of own procsub input, sort shape,
sh child, rubash child, plain-file sibling, 0<&3, last-wins with
both producers running, producer side effect without a consumer)
plus 3 controls green on master (exec / group / {var}). Probe
batteries (33 cells, script files) are byte-identical to GNU Bash
5.3.20 except the pipeline-stage cells, whose stage runners do not
run the ordered own-list application at all — recorded as a
residual in the cluster report.

Refs #2235
# Conflicts:
#	src/executor/command_substitution.rs
#	src/executor/init.rs
#	src/executor/mod.rs
@caomengxuan666
caomengxuan666 merged commit b02f0b6 into master Oct 30, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 30, 2026
Resolve external_inner.rs against #2253/#2263: keep the #2235 stash lookup ahead of the #2270 heredoc arm (a heredoc entry still classifies as write at lookup time, so it can never claim a stash — matching the dup replay, which kind-skips heredocs; a same-fd stash belongs to an earlier plain entry and the heredoc's later stamp preserves last-wins). Semantic check: diff vs master is exactly this PR's change set.

Refs #2270
@caomengxuan666
caomengxuan666 deleted the fix/fd-next-2234-2235 branch November 2, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant