Skip to content

WIP: fix/2042 fd-registry residuals — items 1+5 fixed, 2/3/4 triaged - #2089

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2042-fd-registry-residuals
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2042-fd-registry-residuals

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Issue #2042 lists five fd-registry residuals from PR #2015. Per the batch discipline (triage on current master first, fix the survivors), this branch:

  • Item ① /proc 0644 write EINVAL — FIXED (22d046a1): 0644-class synthetic /proc entries bind the new symbolic FdWriteEndpoint::ProcContentWrite / OutputTarget::ProcContentWrite; in-shell write faces render <name>: write error: Invalid argument (sh_chkwrite channel, builtins/common.c:320-334) exactly like GNU — measured: echo hi > /proc/self/status → echo: write error: Invalid argument, rc 1 on both sides. Exec-level 3> previously created a phantom enclave file; now binds the class. External child face keeps the absorbed sink (no Windows per-write-EINVAL handle; child diagnostics are the child binary's).
  • Item ⑤ file-fd test -r — FIXED (30272772): GNU answers -r TRUE for every live fd magic link regardless of open mode (uid-1 procfs measurement: lr-x regular, l-wx append, lr-x /dev/null all yes). Added the __RUBASH_FD_FILE_<fd> mark + fd_file_test face (-r only, per issue scope), and fixed the fused-scan admission gate which missed the numeric-pid spelling /proc/<pid>/fd/N (rubash#1974) so the first dispatch read stale marks — the gate now asks the registry's own fd_alias_target.
  • Item ② directory-as-stdin external face — 存, 未修: rubash fails at OPEN (Permission denied on the native dir open in open_classified_input's SyntheticLink arm) where GNU opens and the child fails at read (cat: -: Is a directory); this also kills stdin-ignoring commands (ls < /proc/self/cwd must run, rc 0). Root cause pinned in the batch report; the fix needs a child-handle design decision beyond this batch.
  • Item ③ /dev/full ENOSPC child face — 存, platform ceiling: GNU's child prints its own ls: write error: No space left on device (rc 2); Windows has no handle whose writes fail ERROR_DISK_FULL, and rubash cannot honestly forge the child's diagnostic or exit status. Builtin faces already aligned ([bug] /dev/zero、/dev/full 在 Windows 未模拟(打开即失败;/dev/full 丢失 ENOSPC 写形状) #1898).
  • Item ④ builtin-face loopback double-open — 推翻 (not reproducible): a counting TcpListener shows exec 3<>/dev/tcp/127.0.0.1/P performs exactly ONE connection (== GNU's one open per redirect, redir.c do_redirections); the input face likewise one. The probe ladders (>> and <>) bypass special-path registry classification; append probe preempts even external commands; /dev/tcp unreachable through them #1964-era probe-ladder double-open is closed on current master. Incidental (not one of the five): echo hi > /dev/tcp/… reports write error: Invalid argument where GNU's closed-peer shape would be EPIPE — recorded for a future issue.

Verification

  • Oracle: WSL GNU Bash 5.3.x, probes from script files (wsl bash <file> form; wsl.exe arg translation mangles the direct form on this host).
  • A/B matrix per fixed item in the batch report (results/gnu_i*.txt vs results/rub_i*_fixed.txt).
  • cargo test --release: new pins green (issue2042_proc_write_einval_regressions 4/4, issue2042_filefd_test_r_regressions 4/4). Full suite A/B vs pristine 03ae580d: identical results — 5 test targets are pre-broken on Windows (unconditional std::os::unix imports; typed_cell_coherence_fuzz needs debug_assertions), disabled for the run and restored; cli_tests failure set identical to pristine except the dirty-tree version-metadata artifact (both lists archived in the batch report).
  • Disclosure: cargo fmt run explicitly (rustfmt --check clean on all changed files); commits used --no-verify because the pre-commit hook's cargo fmt --check crashes on this host with OS error 206 (command line too long) in the deep worktree path.

Fixes #2042 (items 1 and 5; 2/3/4 verdicts registered here and in the batch report).

  • Batch report + raw artifacts: D:/repo/nbbuild/pkg10/F/REPORT.md, probes/, results/
  • Never self-merged; ready for review.

… like GNU

GNU procfs content files (/proc/<pid>/status, cmdline) are 0644 with no
write handler: the open succeeds and every write fails EINVAL, rendered
by the builtin in its own name via sh_chkwrite (builtins/common.c:320-334;
measured on WSL GNU 5.3.20: "echo hi > /proc/self/status" ->
"echo: write error: Invalid argument", rc 1). The absorbed temp sink made
these writes silently succeed on every bind face.

Mirror the rubash#1898 FullDevice symbolic-endpoint pattern with
FdWriteEndpoint::ProcContentWrite / OutputTarget::ProcContentWrite:
the in-shell write faces render "Invalid argument" through the same
sh_chkwrite channel; the external child face keeps the absorbed sink
(Windows has no per-write-EINVAL handle; the child's own diagnostics
belong to the child binary). Exec-level output binds previously fell
through to a phantom enclave file at the literal path - now bind the
entry's write class.

GNU anchors: proc_vfs.rs proc_content_write_allowed (0644/0444 classes,
measured); procfs content entries answer EINVAL without mutating what a
later read serves (the failed write never lands).

Regression pins: tests/issue2042_proc_write_einval_regressions.rs
(direct write/append, bound 3<> read+write, exec 3> no-phantom, dup class).

Fixes #2042 (item 1 of 5; items 2/3/4 triaged in the batch report).
…ellings

GNU answers "test -r" TRUE for every live /proc/<pid>/fd/N magic link
regardless of the fd's open mode: sh_eaccess (test.c:553 ->
lib/sh/eaccess.c:194) on real procfs says yes for an lr-x read-only
regular file, an l-wx write-only append descriptor, and an lr-x
/dev/null descriptor alike (uid-1 measurement on WSL GNU 5.3.20).
Rubash's pipe-mark face (__RUBASH_FD_PIPE_<fd>, rubash#1467) covered
only pipe handles; a file-backed descriptor fell through to a
filesystem that has no such names and answered false.

Two roots fixed:

- Coverage: file-backed descriptors carry __RUBASH_FD_FILE_<fd>
  (rewritten fresh each call beside the pipe marks), and a new
  fd_file_test face in builtins/test.rs answers -r for a marked fd.
  Only -r is answered - the rest of the unary matrix keeps its
  historical fall-through (issue scope); the pipe class keeps its
  #1467 verdict matrix.

- Admission: the fused-scan gate in execute_test_words hand-listed
  the /dev/fd/ and /proc/self/fd/ prefixes and missed the numeric-pid
  spelling /proc/<pid>/fd/N (rubash#1974 own_pid_fd_tail), so a test
  whose only fd operand was /proc/$$/fd/N skipped the mark refresh
  and read stale marks from a previous dispatch (deterministic false
  at the first test). The gate now asks the registry's own judgment
  (fd_alias_target) - one check for the whole spelling class.

Regression pins: tests/issue2042_filefd_test_r_regressions.rs
(both spellings x read/write binds, first-dispatch freshness, closed
fd stays false, pipe matrix unchanged).

Fixes #2042 (item 5 of 5).
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