Repository navigation
WIP: fd/status propagation — born-closed stdout status (2476) + /dev/fd alias-open cursor (2479) - #2497
Conversation
…ist dup and exec bind (issue2479) GNU bash 5.3 on a HAVE_DEV_FD build serves the /dev/fd/N spelling as a plain open() of the magic link (redir.c:725); the RF_DEVFD F_DUPFD special case (redir.c:603) compiles only without HAVE_DEV_FD. A regular-file target therefore yields a fresh open file description at offset 0, and the same-list <&N dup (make_cmd.c r_dup) shares THAT description, never the ambient source descriptor's. rubash classified two faces as dups of the ambient fd: - the emulated-builtin stdin serve resolved a <&N winner whose source was bound earlier in the same list by an alias OPEN (3< /dev/fd/6) through the ambient-stream verdict, draining fd 6 on the first serve and starving the second; - the persistent exec input arm consulted the dup-target helper first, whose dev-stdio fallback mis-served alias spellings as copy_persistent_input_fd dups, so exec 3< /dev/fd/6 shared fd 6's cursor. The stdin serve now asks whether the winning in-list binding was an alias open (in_list_entry_is_alias_open) and takes the spelling-open fresh serve for a dup of such a binding; dup-bound sources keep the shared-stream serve. The exec arm dispatches a non-dup alias spelling whose ambient endpoint exists to the fresh-open ladder before the dup arm: fresh FileFd for regular files, read-write reopen for <>, dup fallback for endpoints that cannot re-open, and the pre-existing ladder (incl. the closed alias diagnostic) when no endpoint exists. Regression pins: tests/issue2479_devfd_reopen_cursor_regressions.rs (8 pins, GNU 5.3.20 expectations, byte-level; scrubbed-fd run 8/8).
…h status 1 (issue2476) GNU builtins return sh_chkwrite's verdict (builtins/common.c: 319): when the fflush of buffered stdout fails, sh_wrerror prints '<name>: write error: <strerror>' and the builtin returns EXECUTION_FAILURE. A C process born with fd 1 closed keeps it closed, so the flush fails EBADF. rubash exited 0 in silence, through two layers: 1. The Rust runtime sanitizes standard descriptors before main (std::rt::init opens /dev/null over a closed one), so the fd table seeded fd 1 as a live Stdout endpoint and builtin writes 'succeeded' into /dev/null. The fd layer now captures the at-exec descriptor state in a loader constructor (ELF .init_array / Mach-O __mod_init_func, running before the sanitization; fcntl + atomic stores only) and FdTable::new seeds a born-closed fd 1 as closed. A fd 1 genuinely redirected from /dev/null was open at exec and keeps the Stdout endpoint; un-captured platforms keep prior behavior (Windows stub returns false). 2. The listing builtins (declare/typeset, alias, set, export -p, umask, ...) printed the write-error diagnostic from the buffered-write machinery but never folded its failure flag into their status — in-session as well as born-closed. The fold now lives at execute_materialized_command, the one completion point every simple command passes: a set flag lifts a success status to 1, never rewrites an existing failure status, and compound commands are left to their inner commands' own completions. Verified byte-identical to GNU bash 5.3.20 on: echo/printf/ pwd/declare/alias born-closed children (diagnostic + exit 1), inner $? propagation, stderr control, genuine /dev/null control, and the parent-session emitout shape. The in-register pin fd_redirects::c_external_command_reports_write_error_for_ closed_stdout turns green (was red on master). Regression pins: tests/issue2476_born_closed_stdout_ regressions.rs (7 pins, GNU expectations, byte-level; scrubbed-fd run 7/7).
|
[win-acceptance] #2497 PASS (issue2479 face fully verified on Windows; issue2476 face unix-only by design, documented boundary) — issue2479 pin 8/8 x2 @--test-threads=4 on Windows; live probe issue2476 face: pin Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 9348b8d (contains this merge), GNU oracle = |
Refs #2476
Refs #2479
Fix cluster B (fd/status propagation), 1.5.0 gate per 2026-11-02 ruling. Base: frozen master 37eef11.
Commit 1 (issue2479): a /dev/fd/N alias OPEN keeps fresh-open cursor semantics through a same-list <&N dup and through a persistent exec bind. GNU basis: redir.c:725 plain open of the magic link on HAVE_DEV_FD builds (the redir.c:603 RF_DEVFD dup case compiles only without it); <&N itself stays a dup2 (make_cmd.c r_dup). Pins: tests/issue2479_devfd_reopen_cursor_regressions.rs — 8/8 under a scrubbed-fd run. The in-register issue2256 pin file (25 pins, incl. the previously red numbered-bind pin) is fully green.
Commit 2 (issue2476): a process born with fd 1 closed now reports builtin write errors with status 1. Two layers: (a) the Rust runtime reopens a born-closed fd 1 as /dev/null before main, erasing the state GNU's sh_chkwrite (builtins/common.c:319) relies on — the fd layer captures at-exec descriptor state in a loader constructor (.init_array/__mod_init_func) and FdTable::new seeds a born-closed fd 1 as closed (a genuine /dev/null redirect was open at exec and is unaffected); (b) listing builtins (declare/alias/set/export -p/umask) printed the write-error diagnostic but never folded the write-failure flag — the fold now lives at execute_materialized_command, the completion point every simple command passes. Pins: tests/issue2476_born_closed_stdout_regressions.rs — 7/7 scrubbed. The in-register pin fd_redirects::c_external_command_reports_write_error_for_closed_stdout turns GREEN (was red on master).
Local verification is scoped per the wave protocol (cargo check + new pins + named in-register pins, all scrubbed); full-suite verification happens at harvest.
Known surviving adjacent defect (pre-existing on master, NOT introduced here, evidence in cluster REPORT.md): pipeline stage-0 delivery for alias/dup stdin shapes — e.g.
cat < /dev/fd/6 | wc -crun twice prints 12 then 0, andcat 3<&6 <&3 | wc -cprints 0 — identical on unmodified master; belongs to the #2003/#2029 stage-0 materialization family, outside this cluster's two issues.