Skip to content

WIP: fix #2530 #2531 #2532 fd table faces - #2561

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/2530-fd-misc
Nov 2, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/2530-fd-misc

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2530
Refs #2531
Refs #2532

…ription (rubash#2530)

A process born with fd 0 on an O_RDWR file (./child.sh <>file) could
read fd 0 but never write it: FdTable::new seeds fd 0 as
read=InheritedProcessStdin/write=None and register_inherited_process_fds
only adopts fds >= 3, so the write side of the birth descriptor was
never claimed. The seed now probes fd 0's live direction
(fd_directions) and, when writable, installs a dup of descriptor 0
itself as the write endpoint - one open file description, shared
offset, like GNU's r_input_output open (make_cmd.c:682-683
O_RDWR|O_CREAT; redir.c:725 redir_open; redir.c:1160 validates dup
sources against the kernel).

Second face of the same divergence: the <&N descriptor-dup faces
(the fd-0 arm of apply_external_stdin_redirect and the
own-input-binding replay) served the dup through
open_fd_read_endpoint, the alias-SPELLING dispatch, which re-opens a
regular file fresh (redir.c:603/:629 model). A child reading fd 0
through <&0 thus advanced a private offset while its >&0 writes used
the true inherited description. Dup faces now take
open_fd_read_endpoint_stream - the endpoint's own description -
exactly the split that function's contract states; spelling opens
keep the reopen wrapper.

issue2261_child_script_readwrite_fd0_regressions: 9/9 via build slot.
…ash#2531)

deliver_fd_var_dup's at-position resolutions - (1) a binding this
walk already delivered for the source, (2) the fd-0 replay - stamped
only the channel matching the dup's spelling. The ambient stamp loop
runs BEFORE the walk and had already stamped the var's slot from the
applier's ambient copy of the source (it resolves against the
ambient table only), so the unstamped channel kept the ambient
descriptor: {w}>&9 with 9<f9 bound earlier in the same list wrote
through f9's description but read through the ambient fd 9 copy -
GNU's one ordered walk (redir.c:237) dups the descriptor bound at
the dup's position, whole (dup2, redir.c:1193).

Both rungs now stamp the one resolved description on both env
channels with a single dup (stamp_child_fd_description; the child's
restore pairs equal stamped values into one shared FileFd), the
same shape the numbered walk's <> arm already used.

issue2310_scriptface_fdvar_regressions: 8/8 via build slot.
…nix (rubash#2532)

open_files_limit read only the __RUBASH_ULIMIT_N env cell - the
Windows emulation's store. On Unix the ulimit builtin drives the
real setrlimit (builtins/ulimit.rs plat::set) and stores nothing,
so the allocator always fell back to the 10240 default and a
shell-set ulimit -n never bounded {var} allocation: neither the
EMFILE ceiling (ulimit -n 12: the third exec {c}>>f allocated
instead of failing 'Too many open files') nor the below-base
EINVAL (ulimit -n 6: exec {v}</dev/null allocated instead of
failing 'Invalid argument', GNU redir.c:940-946 F_DUPFD bounded by
the current soft limit).

On Unix the allocator now reads the process rlimit back with
getrlimit(RLIMIT_NOFILE) - the same source the builtin reports
from, so the limit the shell set is the limit the allocator
obeys; RLIM_INFINITY maps to unlimited. The Windows env-cell parse
is unchanged.

issue773_fd_table_capacity_regressions: 6/7 via build slot - both
adjudicated pins pass; the remaining red is
emulated_ulimit_defaults_match_oracle, adjudicated PIN-wrong (it
expects the authoring machine's 10240/1048576; this host's ambient
is 4096/4096 and rubash now reports the true ambient, matching the
oracle here).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 2, 2026 05:37
@caomengxuan666

Copy link
Copy Markdown
Member Author

[win-acceptance] #2561 — three faces on Windows (no new pin in this PR; verification = batteries ×2 + issue-repro A/B vs WSL GNU 5.3.20):

  • [fd] 子脚本 <> 只给读端:写 EBADF、文件不创建(#2261 残面) #2530 (child-script <> write side): the write-side faces are FIXED — issue2261_child_script_readwrite_fd0_regressions 6/9 ×2; write_lands and creates_missing now pass. The 3 reds are Windows platform faces, not silent write-loss: (1) shared_offset and cd_anchor_write_side — the pin expects Unix shared-open-file-offset behavior (ab read then PQ write lands at offset 2 → abPQef); on Windows the child's <> handle has an independent file position, so the write lands at EOF (abcdef\nPQ) — a real Windows divergence in the shared-offset semantics to adjudicate separately; (2) directory_fails — the failure IS detected but Windows reports Permission denied where the pin expects the EISDIR wording.
  • [fd] 同 exe 脚本面输出 dup 解析环境表而非列表自身绑定(#2310 残面) #2531 (same-exe script-face output dup resolves own list bind): FIXED. Direct issue-repro A/B byte-identical: exec 9<seed.txt; v=9; CHILD obs.sh {v}<&- 9<f9.txt {w}>&9 with obs.sh cat <&10 → fd10=[F9LINE] rc=0 (the list-position bind, was [SEED]). The issue2310_scriptface_fdvar_regressions battery is 1/8 ×2, but all 7 reds are a test-infra path-form bug on Windows: the driver embeds CARGO_BIN_EXE_rubash with backslashes into the generated driver.sh, and the interpreter eats them (D:repo win-accept...: command not found) — the battery needs the .replace('\\', "/") treatment other harnesses already apply (test-only repair, product verified via the A/B).
  • [fd] {var} 分配器不认 shell 自设的 ulimit -n 软限(#773 残面) #2532 ({var} allocator honors ulimit -n): FIXED. issue773_fd_table_capacity_regressions 7/7 ×2 on this tree, including exhaustion_below_limit_reports_too_many_open_files and base_beyond_limit_reports_invalid_argument.

No BLOCKER to the merge; the shared-offset pair is reported for adjudication. Environment: Windows 10 19045 real machine, MSVC Rust debug build of master b41e8b6 (contains this merge), oracle wsl /usr/local/bin/bash 5.3.20. Probes/logs: D:/repo/win-accept/wave3/probes/p2531.*, D:/repo/win-accept/wave3/logs/.

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