Skip to content

WIP: executor: deliver numbered <> redirects to spawned children as O_RDWR - #2301

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2298-numbered-rw-spawn
Oct 31, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2298-numbered-rw-spawn

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2298

What

A numbered read-write redirect (3<>file) on an external command reached the spawned child as a read-only description: the numbered walk in apply_external_fd_delivery classified RedirectKind::ReadWrite with the input kinds and opened the target through the O_RDONLY input ladder. The child held the slot (reads worked), but a write through it failed EBADF.

GNU: r_input_output opens O_RDWR|O_CREAT (make_cmd.c:682) through redir_open (redir.c:725); do_redirections (redir.c:237) delivers that one description in the forked child.

Change (one file: src/executor/external_inner.rs, +36/−11)

  • The walk now opens <> entries through the classified readwrite ladder (probe_input_redirect_readwrite — the same open the builtin faces use for <>), instead of the input ladder.
  • For a self-opened <> entry, both env channels are stamped with the single dup: the child startup restore pairs equal HANDLE/WHANDLE values into one shared FileFd (init.rs). The pre_exec pin already delivered the descriptor itself to foreign children — it now delivers an O_RDWR one.
  • Stash-backed entries (an earlier entry's description claimed by the fd-0 dup resolution) keep the read-channel stamp only: the stash's access mode is that entry's own.

Because the helper is shared, sequential pipeline stages gain the same delivery.

Pins

tests/issue2298_numbered_readwrite_spawn_regressions.rs (8 pins, unix-gated): write direction via foreign sh (incl. O_CREAT on a missing file) and via a nested rubash child; read direction; one-description shared-offset cells (read a line, write back at the offset — foreign and nested observers); controls for the ambient exec-bound <> face, the write-only 3> spawn face, and the builtin-over-ambient face. Expectations byte-verified against GNU bash 5.3.20 with probe files on master c537d12 (write/nested/shared-offset cells red pre-fix, controls green on both).

Per compile rationing: cargo check (lib + the new test target) clean locally; the pin target itself and PR #2296's corrected issue2261 control pin are for the collector's scrubbed-fd batch.

caomengxuan666 and others added 2 commits October 31, 2026 00:05
Refs #2298

A numbered read-write redirect on an external command reached the
spawned child as a read-only description: the numbered walk in
apply_external_fd_delivery classified RedirectKind::ReadWrite with
the input kinds and opened the target through the O_RDONLY input
ladder, so the child held the slot but a write through it failed
EBADF. GNU r_input_output opens O_RDWR|O_CREAT (make_cmd.c:682)
through redir_open (redir.c:725), and do_redirections (redir.c:237)
delivers that one description in the forked child.

Open <> entries in the walk through the classified readwrite
ladder (probe_input_redirect_readwrite) and stamp both env
channels with the single dup for a self-opened entry — the child
startup restore pairs equal HANDLE/WHANDLE values into one shared
FileFd (init.rs); the pre_exec pin delivers the descriptor itself
to foreign children. Stash-backed entries keep the read-channel
stamp: the stash is an earlier entry's description, whose access
mode is that entry's own.

Pins: tests/issue2298_numbered_readwrite_spawn_regressions.rs —
write / read / one-description-shared-offset cells through foreign
sh and nested rubash observers, plus ambient and write-only
controls. Expectations byte-verified against GNU bash 5.3.20.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 00:35
@caomengxuan666
caomengxuan666 merged commit 872519e into master Oct 31, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2298-numbered-rw-spawn 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