Skip to content

WIP: #2359 engine special-path faces (/dev/fd, /dev/std*, /dev/tcp|udp) vs GNU bash 5.3 - #2383

Merged
caomengxuan666 merged 7 commits into
masterfrom
fix/2359-dev-paths
Oct 31, 2026
Merged

caomengxuan666 merged 7 commits into
masterfrom
fix/2359-dev-paths

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2359

Finisher #2 on cluster S2. Stack: preservation commit 68c71a91 (the original agent's uncommitted work, pushed verbatim by finisher #1) + 5 adjudication/fix commits. Full per-face table, inherited-work adjudication, and verification evidence: ~/workspace/fix-2359-dev-paths/REPORT.md (cluster report; summary below).

Faces fixed on top of the preserved work

  • $(</dev/tcp|udp/…) cat shortcut connected (TCP read the banner; UDP blocked forever). GNU's shortcut is a plain open (subst.c:6666 → builtins/evalstring.c:759/:781) — net arm removed; spelling now fails ENOENT like GNU. The [bug] $(<file) 快读梯缺 proc/net 步:$(</proc/meminfo) 失败而 cat 正常 #1904 regression pin encoding the banner read was corrected with the citation.
  • Brace-group redirect failure lost its status: refusal printed once but the group reported 0 (&& ran, || skipped, set -e ignored) — the AST brace IoError arm fell through to a re-dispatch that reset the status. Arm now consumes the command with the errexit promotion.
  • Pipeline stages ignored numbered-fd noclobber refusals: the inherited preflight flag was never set and its consumer was unreachable behind the defer blanket. Flag armed; gate reordered (stage spellings judged against the stage, numbered fds against the ambient resolver).
  • Alias resolver keyed on descriptor numbers instead of descriptions: generalized to endpoint-keyed arms — /dev/stdin with stdin a character device (/dev/null) now opens the device (was EBADF); exec 3>&1 spellings resolve to stdout's file incl. in stages; exec 3<&0 spellings resolve to stdin's file.

Verification (local, scrubbed-fd runner where fd-sensitive)

Remaining face (documented model gap, not fixed here)

Complementary-end opens of pipe endpoints (s02/u01/u02 probes): GNU's open of a pipe read end's /proc/self/fd/N in write mode materializes the pipe's other end in the kernel. rubash materializes procsub streams as in-memory TextInput with no appendable channel and inherits stdin as a direction-locked virtual endpoint; no OutputTarget variant can carry such a write channel (external stages have none at all). Needs an appendable byte-channel endpoint kind — an engine design item.

Draft — do not merge; main session collects.

Preservation commit by finisher: uncommitted state left by the original
S2 agent (executor /dev-fd alias handling, special_paths, pin file).
Adjudication against GNU bash 5.3 source follows in later commits.

Refs #2359
GNU's $(<file) shortcut is optimize_cat_file (subst.c:6666) over
open_redir_file (builtins/evalstring.c:759): a plain open(fn, O_RDONLY)
at evalstring.c:781 that never consults redir.c's special-filename
table. The #1904 ladder arm in comsub_cat_file_substitute CONNECTED
for /dev/tcp|udp spellings — returning a live server's banner where
GNU fails ENOENT, and blocking forever reading a UDP peer.

The spelling now falls through to the plain filesystem read and
fails there. The fd-table, null-device and synthetic-/proc arms of
the ladder stay: the OS open behind GNU's call resolves those
itself on a HAVE_DEV_FD / HAVE_DEV_STDIN build.

tests/regression.rs: the #1904 tcp pin asserted the banner read;
rewritten to the GNU contract (live listener, never accepted from)
with the correction recorded in the module doc. Sibling #1904 pins
(proc content, /dev/null) are unaffected.
The inherited preflight twin (pipeline_stage_output_redirect_fails)
added OutputFdState::preflight_stage_stdio so a stage's alias
spellings are judged against the stage's bindings — but nothing
ever set the flag, and the only consumer sat behind the gate's
defer_stdout_writes blanket return, unreachable. Stage faces with a
numbered fd on a regular file (echo x > /dev/fd/3 | cat, set -C)
wrote through where GNU's stage child refuses the fresh open
(redir.c:676 noclobber_open over redir_open's plain open).

command_output_redirect_fails_impl now arms the flag for stage
preflights, and dev_stdio_target_reopens_disk judges in order:
preflight stdio spellings (fd 0/1/2) against the stage, preflight
numbered fds against the ambient resolver, then the defer blanket
for the routing walks. Probes s06/s07/u06 byte-match GNU bash
5.3.20; stage fd-1 spellings still name the stage pipe.
{ echo x; } > /dev/stdout under set -C with stdout a regular file
printed the noclobber refusal once but the group reported status 0:
the AST loop's brace IoError arm reported the failure and set
exit_code=1, then fell through to execute_simple_pipeline, whose
re-dispatch of the same group reset the status to 0 — && ran its
right-hand side, || skipped its own, and set -e did not exit.
Subshell/loop/if/function faces were already correct.

The arm now consumes the command like the Ok(true) arm
(skip_and_or_rhs + close region + continue) with the
ExpansionFailure arm's errexit promotion — the same ending that
arm's comment documents for this exact fall-through hazard
(rubash#1240). GNU: the refused group fails with status 1 and
drives the lists (redir.c do_redirections failure reached from
execute_cmd.c's brace-group execution). Probes r03/e/e3
byte-match GNU bash 5.3.20.
fd_alias_reopen_path keyed its stdio arms on descriptor NUMBERS
(fd == 0/1/2). An alias open names the open file DESCRIPTION the
number carries, so three GNU faces diverged:

- > /dev/stdin with stdin a character device (/dev/null): the arm
  required a regular file, and disk_file_path answers regular files
  only by design (src/fd/unix.rs) — the face fell to the dup serve
  and the builtin's flush failed EBADF. The arm now accepts a
  character device; its path comes from the /proc/self/fd/0 magic
  link. Pipes/sockets earn no path (their link text is the
  pipe:[ino] form, which fails the metadata test) — the
  complementary-end shapes keep the dup serve.
- exec 3>&1, then > /dev/fd/3 (also inside a pipeline stage):
  fd 3's write endpoint is Stdout but the fd==1 arm missed it, so
  the stage wrote into its pipe where GNU refuses (stdout a
  regular file, set -C). The Stdout/Stderr arms are now keyed on
  the endpoint for any fd.
- exec 3<&0, then > /dev/fd/3 with stdin a regular file: the
  inherited-stdin arm is likewise endpoint-keyed (any fd whose
  read endpoint is InheritedProcessStdin), not fd == 0.

Probes r07/t31/t32 byte-match GNU bash 5.3.20; all probe rounds
re-run clean except the pipe complementary-end class (documented
in the cluster report as the remaining model gap).
…e/dup faces, stage dup refusals

Seven pins added: the cat shortcut's ENOENT for TCP and UDP
spellings against a live listener; the brace group's failure
status across plain/&&/||/set -e shapes; writes through /dev/stdin
and /dev/fd/0 with stdin the null device; the stage refusal for an
append-mode fd 3; the stage refusal for a stdout-dup fd 3
(exec 3>&1); fresh-open writes through a stdin file and through a
stdin dup (exec 3<&0).

One inherited pin corrected: the /dev/stderr sub-case of the
stdio-spellings refusal test expected a refusal under a harness
that leaves stderr a PIPE — with stderr a pipe GNU writes through
(oracle-verified). The sub-case now runs under a new stderr-file
harness and asserts the file shape. Suite: 16 passed / 0 failed
under the scrubbed-fd runner.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 16:28
@caomengxuan666
caomengxuan666 merged commit c3b9412 into master Oct 31, 2026
@caomengxuan666
caomengxuan666 deleted the fix/2359-dev-paths branch November 2, 2026 01:09
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