Skip to content

fix7 fd-source slice: fd delivery to external children, source /dev/stdin fd-0 binding, bare builtin redirections - #1689

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix7/slice-fd-source
Oct 26, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix7/slice-fd-source

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix7 fd-source slice: deliver shell fds to external children; source /dev/stdin honors the command's fd-0 binding; bare builtin performs its redirections.

Three commits cherry-picked from the fix7/fd-source cluster branch onto master 9c90ab9 (zero conflicts). Cluster report: ~/workspace/rubash-fix7/clusters/fd-source/REPORT.md, probes in the same directory.

Contents

  • [bug] External commands cannot see fds opened persistently with exec (EBADF; missing from child fd table) #1626 — spawn_external_process only handed fds ≥3 to children through the __RUBASH_FD_* env channel, which only rubash children restore; real external children (with all handles O_CLOEXEC) always saw EBADF for exec-opened fds. On Unix, spawn now pins each real-descriptor-backed ambient fd to its own slot number via a two-phase pre_exec (F_DUPFD_CLOEXEC lift, then dup2 onto the slot). Slots the command itself redirects are skipped (the more local binding wins — pinned by a "never write to the wrong file" safety test), as is spawn's own exec-error pipe slot. Non-Unix keeps the env channel.
  • [bug] source /dev/stdin with file/herestring stdin redir reads nothing (GNU executes it) #1642 — source /dev/stdin only consulted the pipeline buffer and the process stdin handle; a command-level fd-0 binding (<<<, <<EOF, < file) lives in the virtual fd table and was never read, so the source silently ran empty with rc=0. The branch now resolves through the executor's existing stdin ladder (same ladder as read/cat, with the fd-table shadowing rules); a command that carries an fd-0 redirect resolving to nothing sources empty text instead of falling back to the process stdin GNU would not touch.
  • [bug] bare builtin with redir-only ignores output redirections (GNU performs them) #1643 — bare builtin with no name argument returned rc=0 without applying the command's own redirections. It now calls the same redirect helper the :/true/false arms use; redirect failure sets rc=1. The builtin -- > f form lands in the same branch and is fixed with it.

Out of scope (Refs only — filed separately, do NOT close with this PR)

Refs #1686
Refs #1687
Refs #1688

These are adjacent gaps recorded by the cluster: command-level fd redirects are likewise not delivered to external children (#1686); numbered-fd redirects (3>) missing for bare builtin and : (#1687 — the #[ignore] GNU-expectation pin issue1643_bare_builtin_numbered_fd_redirect_known_gap in this slice's #1643 test file stays ignored until it lands); pipeline members do not inherit ambient fds (#1688 — the #[ignore] pin issue1626_exec_fd_listed_in_pipeline_child_known_gap in the #1626 test file likewise).

Verification (on the landed tree)

To be filled in by the integration verification comment: targeted three test files, full lib suite, 306-case differential, redir-fd regression surface.

Fixes #1626
Fixes #1642
Fixes #1643

@caomengxuan666

Copy link
Copy Markdown
Member Author

Update per the 2026-10-26 fd-source dual-route ruling (DECISIONS.md; full comparison in the collab review report §3): this slice is the landing route for #1642/#1643; the single-issue PRs #1682/#1685 will be closed as incorporated after this merges.

Added one tests-only commit (8577d42) pinning the two test shapes that only #1685 carried, into tests/issue1642_source_dev_stdin_regressions.rs:

  • issue1642_source_dev_stdin_explicit_redirect_wins_over_pipe — explicit fd-0 redirection wins over piped process stdin
  • issue1642_source_dev_fd0_alias_here_string — /dev/fd/0 alias spelling

No production code change. Targeted expectation for the verification run is now 30 passed / 0 failed / 2 ignored (the two ignored pins remain the #1687/#1688 known-gap pins). Full gate results will be posted as a verification comment before merge.

…lot numbers (rubash#1626)

The fd table's descriptors reached only rubash children via the
__RUBASH_FD_* env channel; foreign children got EBADF for every fd
bound by exec N>file / N<file / N<>file, and the handles are opened
O_CLOEXEC so nothing leaked through the raw fd space either. On Unix
the spawn path now registers a pre_exec pin that dup2's each ambient
fd-table descriptor (File/Coproc endpoints) onto its slot number in
the child, mirroring GNU fork inheritance. Slots the command itself
redirects are skipped (its binding is the more local one), and the
spawn machinery's own exec-error pipe is never clobbered.

Regression tests: tests/issue1626_exec_fd_child_visibility_regressions.rs
(9 pass; the pipeline-member listing form is pinned #[ignore] as an
adjacent gap — pipeline spawns do not pass through this path).
…bash#1642)

The /dev/stdin arm consulted only the pipeline stage buffer and the
process stdin handle, so source /dev/stdin <<< '...' and
source /dev/stdin < file silently sourced nothing — the command's
fd-0 binding lives in the command node / virtual fd table and never
reaches the process handle. The arm now resolves through the same
stdin ladder every other consumer uses (command stdin text via
stdin_string_for_command, exposed to builtins as command_stdin_text),
and when the command carries its own fd-0 redirection that resolves
to no text it sources nothing instead of falling through to a stdin
GNU would not consult.

Regression tests: tests/issue1642_source_dev_stdin_regressions.rs
(11 pass; pipeline / process-stdin / function / compound forms are
controls that already worked).
The no-name arm of execute_builtin_direct_command returned success
without applying the invocation's redirections, so builtin > f
created nothing. GNU performs the command node's redirections
regardless of the named builtin; the arm now runs the same
apply_no_output_builtin_redirects_with_status helper the
:/true/false arms use, with status 1 on redirect failure.

Regression tests: tests/issue1643_bare_builtin_redirect_regressions.rs
(8 pass; the numbered-fd 3> form is pinned #[ignore] — the shared
helper walks only the stdio fields, a gap bare ':' shares).
…6-10-26)

Tests-only incorporation per the fd-source dual-route ruling
(~/workspace/collab-pr-review/REPORT.md §3.2): the slice takes the
route, and the two test shapes only the single-issue PR #1685 carried
are pinned in the slice's regression file before #1685 is closed as
incorporated:

- explicit fd-0 redirection wins over piped process stdin
  (GNU: redir.c binds fd 0 before the builtin runs)
- /dev/fd/0 alias spelling of the same binding

No production code change; the slice's read-only stdin ladder already
resolves both shapes (redirect_cmd before FUNCTION_STDIN; /dev/fd/0
shares the /dev/stdin matches arm).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Integration verification — all gates green on the landed tree (master 38062f5 + this slice, head b38e59b; all cargo runs through the single build slot, JARVIS_*-purified env, JOBS=1, debuginfo=0):

Gate Result
Build (cargo build --locked) OK (only the 4 pre-existing debugger-skeleton warnings)
Targeted: issue1626 / issue1642 / issue1643 files 30 passed / 0 failed / 2 ignored (9/1, 13/0, 8/1)
Ignored pins exactly the two known-gap pins: issue1626_exec_fd_listed_in_pipeline_child_known_gap (#1688), issue1643_bare_builtin_numbered_fd_redirect_known_gap (#1687)
redir-fd regression surface (issue1590–1595, guards the #1626 pre_exec pin) 20 passed / 0 failed
lib full (--skip login_posix_env) 771 passed / 1 failed / 1 ignored — sole failure ownership_unary_operators_check_existing_file, the standing baseline item
Differential corpus 306 305 PASS / 1 FAIL — failure set {ms10} (known-stable), no new failures
rustfmt (per changed file) / CR bytes / continuation.rs clean / 0 / untouched

Notes: the two tests added by the tests-only commit (8577d42, rebased to b38e59b) — explicit redirect wins over pipe, /dev/fd/0 alias — are inside the 13/13 green of the #1642 file. During verification master advanced twice (#1670 history-eng, then #1647 perf-parse, then #1701 expand-param); the slice was rebased onto 38062f5 and the full gate set re-run on that tree. The final merge adds only #1701, which has zero file overlap with this slice (verified by diff). Merging now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant