Repository navigation
WIP: #2492 procsub producer inherits ambient std-stream fds on every platform (exec 8<&0 + <(... <&8)) - #2504
Conversation
…m (rubash#2492) GNU basis: `exec 8<&0` is the dup branch of do_redirection_internal (redir.c:1192 — `dup2 (redir_fd, redirector)`), leaving fd 8 on the process stdin's open file description, and process_substitute (subst.c:6362, make_child at subst.c:6412) is a pure fork: the child inherits that descriptor whole, reads through it consume the same description, and `exec 0<&8` inside the child is a legal dup. Residual of #2471's half (a): spawn_input_process_substitution_child (executor/trap_exec.rs) had its ambient `__RUBASH_FD_*` pass behind #[cfg(unix)] — the Windows streamed producer spawn delivered NO ambient fd at all, std-stream or File, so after `exec 8<&0` a `<( ... <&8 ... )` body failed with `8: Bad file descriptor` (the modernish _Msh_loopgen `exec 0<&8` face). issue2212 pin 08 covered the collected comsub route (body runs in-process), so the Windows streamed spawn was never exercised. Fix: the pass now runs on every platform. On Unix nothing changes (the pins still dup2 each dup onto its slot in pre_exec); on Windows std's plain Command::spawn sets no PROC_THREAD_ATTRIBUTE_HANDLE_LIST (verified in the rustc 1.99 toolchain source — STARTF_USESTDHANDLES with bInheritHandles=TRUE), so the stamped inheritable dups cross at their own handle values, exactly what the child's init already trusts verbatim (init.rs, "Windows handle values transfer verbatim across CreateProcess inheritance") — the same transport the output form's plain spawn (external_setup.rs) uses. Std-stream endpoints arrive materialized through ambient_procsub_spawn_fd's standard_backing dup (#2212), so `8<&0` / `8<&1` / `8>&2` all ride as Files. Verification (WSL GNU Bash 5.3.x script files, stdin fed both sides — the fd is a dup of stdin, an unfed run blocks GNU in the child's read <&8): - repro byte-identical (parent got: [child sees fd8: [DATA-LINE]] / [ child exec 0<&8 ok]). - matrix {8<&0, 8<&1, 8>&2} x {<(...), >(...)} x {read / write / exec dup}: 6 semantic cells byte-identical on stdout/stderr or the side-file channel; artifacts under target/issue-suites/results/issue2492/. - new pins tests/issue2492_procsub_std_endpoint_fds.rs: 6/6. - issue2212 14/14, issue2292 18/18; issue2195 reds (7) verified identical on clean master 37eef11 (pre-existing Windows consumer-face gaps); cargo test --lib parity with clean master: 1124 passed / 2 failed / 3 ignored on BOTH trees (same 2 pre-existing reds). Hook note: committed with --no-verify because the repo-wide `cargo fmt --check` fails with os error 206 on this machine in the pristine main checkout too (argument line over the Windows limit with this many test targets) — the hook cannot execute here. Both staged files verified with per-file `rustfmt --edition 2021 --check`: clean, except one PRE-EXISTING master-side diff in trap_exec.rs at line 387 (present on committed master, untouched). Refs #2492 #2471 #2480
0d0da49 to
58567ad
Compare
|
[win-acceptance] #2504 PASS — new pin 6/6 x2 @--test-threads=4; issue #2492 repro (stdin fed on both sides) byte-identical to WSL GNU Bash 5.3.20: Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 6e06070 (= this PR's merge step), GNU oracle = This is the cfg(windows)-face PR (the The PR body's adjacent pre-existing gap (single No BLOCKER. |
WIP: #2492 — procsub producer delivers ambient std-stream-endpoint fds on every platform. Do not merge (captain harvests).
Refs #2492 #2471 #2480
Root cause (one sentence)
spawn_input_process_substitution_child(src/executor/trap_exec.rs) had its ambient__RUBASH_FD_*delivery pass behind#[cfg(unix)], so the Windows streamed<(...)producer respawn carried NO ambient fd at all — and sinceexec 8<&0binds the symbolicFdReadEndpoint::InheritedProcessStdin, fd 8 never reached the body, which then reported8: Bad file descriptorat bothread <&8andexec 0<&8.This is the residual half (a) of #2471 on Windows: the std-endpoint materialization (
ambient_procsub_spawn_fd->standard_backingdup, external_setup.rs) and the consumer-side ambient loop landed there, but the producer-side pass stayed Unix-only. issue2212 pin 08 only exercises the collected comsub route (body runs in-process), so the streamed Windows spawn was never covered.GNU basis (C source citations)
redir.c:1192-1193do_redirection_internal()dup branch:dup2 (redir_fd, redirector)—exec 8<&0leaves fd 8 on the process stdin's open file description.subst.c:6362 process_substitute(),make_childatsubst.c:6412— a pure fork: the child inherits the whole fd table, reads through fd 8 consume the same description, andexec 0<&8inside the child is a legal dup.Fix
The producer's ambient pass now runs on every platform (trap_exec.rs): the env-stamp loop drops its
#[cfg(unix)](only the Unix pre_exec dup2 pins stay platform-gated). On Windows, rustc 1.99 std's plainCommand::spawnsets noPROC_THREAD_ATTRIBUTE_HANDLE_LIST(verified in the toolchain source —STARTF_USESTDHANDLESwithbInheritHandles=TRUE), so the stamped inheritable dups cross at their own handle values — exactly what the child's init already trusts verbatim (init.rs, "Windows handle values transfer verbatim across CreateProcess inheritance"), the same transport the output form's plain spawn (external_setup.rs:3333) already uses. Std-stream endpoints (8<&0/8<&1/8>&2) arrive materialized throughambient_procsub_spawn_fd'sstandard_backingdup (#2212), so they ride as Files. No new transport, no new guards — the existing design extended to the platform it skipped.Matrix (WSL GNU Bash 5.3.x vs rubash, script files, stdin fed on BOTH sides — the fd is a dup of stdin, an unfed run blocks GNU in the child's
read <&8)exec 8<&0<(...)producer<&8+exec 0<&8exec 8<&1<(...)producer<&8(fails rc 1) +exec 0<&8(ok)exec 8>&2<(...)producer>&8+exec 2>&8exec 8<&0>(...)consumerread <&8exec 8<&1>(...)consumerread <&8(fails rc 1)exec 8>&2>(...)consumer>&8The issue's repro is now byte-identical:
parent got: [child sees fd8: [DATA-LINE]]/parent got: [ child exec 0<&8 ok]. Raw artifacts:target/issue-suites/results/issue2492/(cases/, out/, run_matrix.sh).Adjacent pre-existing gap observed while matrixing (NOT this PR's scope, fd-independent — reproduced with no ambient fd at all): a single
echo start > >( read payload; echo ... )body's STDOUT never surfaces under rubash (payload:[start]on GNU); the body runs, its side files and stderr writes land (pinned by the consumer cells above). Same family as the known-red issue2195 Windows faces; likely for the #2234 live-pipes cluster.Verification
tests/issue2492_procsub_std_endpoint_fds.rs: 6/6 (stdin fed explicitly in the harness).#![cfg(unix)], no-op on Windows).cargo test --libparity with clean master, on BOTH bases: old base 37eef11 and current master 2f566a0 — fix tree 1124 passed / 2 failed / 3 ignored vs master 1124/2/3, same 2 pre-existing reds (api::consumer_tests::issue2084_session_end_restores_host_process_state,executor::tests::unit_tests::shell_identity_is_used_for_default_dollar_zero).Disclosures
cargo fmt --checkfails with os error 206 on this machine (reproduced in the pristine main checkout — the rustfmt argument line exceeds the Windows limit with this many test targets), so the pre-commit hook cannot execute. Both files in this PR were verified with per-filerustfmt --edition 2021 --check: clean, except one PRE-EXISTING master-side diff in trap_exec.rs at line 387 (present in committed master, untouched here). Local commit therefore used--no-verifywith this disclosure.github.com:443is TCP-blocked from this machine right now (api.github.com and codeload.github.com reachable), sogit pushcannot run. The remote branchfix/2492-procsub-std-endpoint-fdwas built through the GitHub Git Data API (blobs + tree + commit directly on parent 2f566a0); its content is byte-identical to the locally verified tree (blobs uploaded fromgit showof the verified commit). If the network recovers, the captain can force-push the local history over it without content change.git stash popin this worktree popped ANOTHER session's stash entry (the stash stack is shared across the 20+ worktrees). The foreign 4-file WIP (fix/procsub-fd-arg: function_env.rs, ast_print.rs, nodes.rs, token_actions.rs) was restored UNTOUCHED to the shared stack asstash@{0}with message "recovered untouched: fix/procsub-fd-arg 4-file WIP...", and a patch copy sits at the wt-2492 machine's/tmp/wt2492_foreign_4file.patch. Owners may want a per-worktree stash discipline.