Repository navigation
WIP: /dev/fd/N alias open of a regular file re-opens fresh (#2256) - #2275
Merged
Merged
Conversation
Refs #2256 GNU's alias open is the plain open() of the magic link: redir.c's RF_DEVFD dup special case (_redir_special_filenames, redir.c:603; the F_DUPFD serve at redir.c:629) compiles only without HAVE_DEV_FD, and the oracle build defines HAVE_DEV_FD 1 — so the endpoint's kind decides. A regular file re-opens its target (new open file description, offset 0, the source descriptor's mode and offset irrelevant); pipes, sockets, devices and byte channels cannot be re-opened and keep the dup/stream model. The <&N/>&N instructions stay dup2 on every kind. The dispatch lives once in the alias layer: Executor::fd_alias_reopen_path answers the re-open path for a regular-file endpoint (read endpoint, then write endpoint, then fd 0's inherited regular-file stdin), gated by FileFd::reopens_fresh (disk-file handle whose stored path itself names a regular file, which keeps the /dev/zero pump file and other synthetic spellings out). Consumers routed through it: open_fd_read_endpoint (the old body is kept verbatim as open_fd_read_endpoint_stream for the dup instruction and for fd 0's own-stream consumers), the redirect walk's input and output alias arms (the output arm also takes the noclobber verdict against the target, naming the spelling, as GNU does), set_fd_readwrite_file's <> alias arm (one O_RDWR pair), bind_conditional_stdio_redirects' output arm, the function-call fd-0 bind, the stdin string channel's spelling face, and the /dev/fd operand faces (in-process byte/live-file serves; the Windows operand materialization no longer records the EOF consume for a re-opened file). External-child faces already split correctly (<&N dups in the &-gated arms, spellings take open_input_redirect) and are unchanged. Regression pins: tests/issue2256_devfd_fresh_open_regressions.rs (24 pins; GNU Bash 5.3.20 oracle transcripts in the cluster probes). Local verification is cargo check / cargo check --tests only, per the compile-rationing rule — CI owns the test runs.
…pen resolver (rubash#2256 wave 2) Wave 1 split alias endpoints by type but several faces still served the shared description where GNU open()s fresh: - ordered output walk: the reopen gate (dev_stdio_target_reopens_disk) and open_command_output_target consulted only the source WRITE endpoint, so a read-bound source (> /dev/fd/6 with 6<file) fell into the dup shortcut (EBADF on flush) and never got the noclobber refusal. Both now source the fresh path from fd_alias_reopen_path, with the O_EXCL refusal reported through the walk protocol. - write_dev_stdio_redirect_output (builtin flush face): a regular-file alias now writes through a fresh open (truncate/append per the caller arm, noclobber refusal included) instead of the shared endpoint; callers pass their arm mode. - read builtin: the redirect_in alias arm in read_input_for_command and read_redirected_fd serve a spelling (< /dev/fd/N, kind Input) from a fresh FileFd scratch endpoint; dup words keep sharing. - source: sourced_dev_fd_text asks the resolver before the snapshot serve, so source /dev/fd/N on a file-bound N reads the file fresh instead of falling through to a literal-path ENOENT. - operands: dev_fd_operand_bytes serves fd 0 fresh when the process stdin is a regular file (resolver fd-0 arm) instead of draining it. - spawn binds: own_input_binding_before binds a fresh FileFd for an alias-spelling input entry (3< /dev/fd/6) instead of the source endpoint; the stash still gives a same-list <&N dup the one shared description GNU dup2s. - stdin_string_for_command: the FUNCTION_STDIN arm for <&0 no longer fires when fd 0 holds a real File endpoint (function <> bind, exec rebind) — the dup serves that endpoint. Fixes the issue2249 pin shape on the composed tree (GNU oracle verified: the pin expectation is byte-identical to GNU 5.3.20). Refs rubash#2256, rubash#2249.
caomengxuan666
marked this pull request as ready for review
October 30, 2026 22:53
This was referenced Oct 30, 2026
SpookyWaste
pushed a commit
to SpookyWaste/rubash
that referenced
this pull request
Nov 12, 2026
…argets Refs unixwin#2285 `exec 6<seed; /bin/echo X > /dev/fd/6` wrote X to the shell's real stdout and left seed untouched: the stdio plan classified the alias PATH spelling as a dup source, found no write endpoint on the read-bound binding, and declined; the legacy stdio arms then fired on no branch (not closed, not a stdio dup, no output endpoint, and the plain-open arm requires a non-fd target). GNU spec: with HAVE_DEV_FD defined, redir.c's RF_DEVFD dup special case (redir.c:602-629) does not compile, so an alias spelling under an output instruction takes the plain open in redir_open (redir.c:725, via do_redirections at redir.c:237) — a FRESH open of the resolved regular file, truncate/append per the instruction, noclobber-refused under set -C, regardless of the source endpoint's direction or offset. Oracle-verified against GNU bash 5.3.20, including the read-write and write-bound source shapes (fresh + truncate in both; the issue text's shared-offset control claim for `6<>file` is falsified — the `>&N` dup spelling is the shared-offset one and is unchanged). Fix: one shared resolver in the alias layer (Executor::open_alias_spelling_fresh_output + open_fresh_alias_file, the File-returning twin of the buffered face's write_fresh_alias_file_output from unixwin#2275), consulted by the stdio plan's Output/Append/ClobberOutput arm (fds 1/2) and by the four legacy stdio arms (stdout/stderr x truncate/append), placed after the stdio-dup arms so the piped-fallback routing is not preempted. Dup spellings (`>&N`, `>&-`) never reach the resolver. Pins: tests/issue2285_external_alias_output_regressions.rs — the reproducer, append (contents preserved), read-write and write-bound fresh controls, noclobber refusal with target untouched, the fd-2 form, and a `>&6` dup-spelling shared-offset control. GNU expectations from probes/oracle-pins.sh (cluster workdir).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2256
Model
GNU's alias open is the plain open() of the magic link: redir.c's RF_DEVFD dup special case (
_redir_special_filenames, redir.c:603; the F_DUPFD serve at redir.c:629) compiles only without HAVE_DEV_FD, and the vendored oracle build defines HAVE_DEV_FD 1. So the endpoint's kind decides:<&N/>&Ninstructions stay dup2 on every kindShape
One dispatch in the alias layer:
Executor::fd_alias_reopen_path(read endpoint → write endpoint → fd 0's inherited regular-file stdin), gated byFileFd::reopens_fresh(disk-file handle whose stored path itself names a regular file — keeps the /dev/zero pump file and other synthetic spellings out). Consumers:open_fd_read_endpoint(old body kept verbatim asopen_fd_read_endpoint_streamfor dup/stream consumers), the redirect walk's input/output alias arms,set_fd_readwrite_file's<>alias arm,bind_conditional_stdio_redirects, the function-call fd-0 bind, the stdin string channel's spelling face, and the /dev/fd operand faces (incl. dropping the Windows operand EOF-consume for re-opened files). External-child faces already split correctly and are unchanged.Verification
tests/issue2256_devfd_fresh_open_regressions.rs.cargo checkandcargo check --testslocally only (both clean); GitHub CI owns the test runs and the main session collects.Discoveries and deferred faces (socket ENXIO divergence, pipeline-stage alias binds owned by the #2255 line, split-endpoint corner) are recorded in the cluster REPORT.md for the main session — no new issues filed from here.