Skip to content

WIP: fix(fd): numbered /dev/null spawn delivery + BASH_SOURCE bare-name resolution (#2304, #2302) - #2312

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/fd-tail-2304-2302
Oct 31, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/fd-tail-2304-2302

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2304, Refs #2302 — two small diagnosed fixes from the fd/invocation tail wave. One commit per issue. Local commits only: push pending credential restore (gh token 401 at delivery time).

#2304 — numbered /dev/null redirects skipped on the spawn face

apply_external_fd_delivery's skip bundle (from #180) dropped every numbered redirect whose target is_null_device, so sh -c '…' 3</dev/null / 3>/dev/null / 3<>/dev/null gave the child EBADF at the slot. GNU hands every file target to redir_open (redir.c:949) and /dev/null takes the plain open with the kind's flags (redir.c:745; <> = O_RDWR|O_CREAT, make_cmd.c:682). The fix removes the null arm from the skip — all three ladders below it own the null class explicitly and return a real descriptor of the mapped device (open_classified_input's null arm, create_redirect_output's null arm, probe_input_redirect_readwrite's NullDevice fall-through).

Pins: tests/issue2304_numbered_devnull_spawn_regressions.rs (5) — foreign sh observer for all three kinds, nested-rubash observer, stdio control. Red on master, green with the fix; probe table byte-identical to GNU bash 5.3.20.

#2302 — bare-name PATH invocation recorded the bare name in BASH_SOURCE[0]

GNU records the path actually opened on both faces (command face: find_user_command's full_path replaces the typed word in shell_execve's ENOEXEC re-exec, execute_cmd.c:6237-6260; program face: open_shell_script replaces filename with the PATH find, shell.c:1595-1597, push_source at shell.c:1640), while $0 splits by face (command face resolved; program face as spelled, shell.c:1613).

  • execute_enoexec_shell_script: a slash-less word now seeds the reader name from the find_user_command result (program) instead of the typed word; slash words unchanged.
  • main.rs run_script_file_with_init: when find_script_on_path supplies the file, __RUBASH_SCRIPT_NAME (the reader-name carrier seeding BASH_SOURCE + diagnostic names) takes the found name; BASH_ARGV0 ($0) keeps the spelled name.

Pins: tests/issue2302_bash_source_bare_name_regressions.rs (7) — command-face bare/direct/err-prefix, program-face bare/err-prefix, slash-spelling control, not-in-PATH refusal control. Red on master, green with the fix; probe table byte-identical to GNU bash 5.3.20.

Verification (collector-local, scrubbed fd environment)

  • issue2304 target 5/5, issue2302 target 7/7
  • controls: issue2272 24/24, issue2255 14/14, issue2298 8/8, issue2292 18/18
  • --test regression: 221 passed + exactly the 6 known local stock reds (master-red locally, green in CI)

caomengxuan666 and others added 4 commits October 31, 2026 01:33
The spawn-delivery walk (apply_external_fd_delivery) skipped every
numbered redirect whose target is the null device — a guard bundled
into the #180 walk before the classified open ladders existed — so
`3</dev/null`, `3>/dev/null` and `3<>/dev/null` on an external
command left the child with EBADF at the slot.

GNU do_redirection_internal hands every file target to redir_open
(redir.c:949 do_redirection_internal) and /dev/null is not one of
redir.c's special filenames, so it takes the plain open with the
kind's flags (redir.c:745 redir_open; `<>` is O_RDWR|O_CREAT,
make_cmd.c:682) and the descriptor is delivered like any file's.

Drop the null arm from the skip: all three arms below own the null
class explicitly and return a real descriptor of the mapped device
(open_classified_input's null arm, create_redirect_output's null
arm, probe_input_redirect_readwrite's NullDevice fall-through to
the raw mapped open).

Pins: tests/issue2304_numbered_devnull_spawn_regressions.rs —
foreign sh observer for all three kinds, a nested-rubash observer,
and a stdio control. Byte-verified against GNU bash 5.3.20.

Refs #2304
…ripts

A script invoked by bare name and found through PATH recorded the
bare name in BASH_SOURCE[0]. GNU records the path actually opened
on both invocation faces:

- command face: execute_disk_command resolves the word through
  find_user_command (findcmd.c:247 find_user_command;
  findcmd.c:623 find_user_command_in_path returns the PATH-joined
  full_path) and shell_execve's ENOEXEC re-exec replaces the typed
  word with that resolved name (execute_cmd.c:6237-6260
  shell_execve), so $0 (shell.c:1613), the BASH_SOURCE push
  (variables.c:5718 push_source, via shell.c:1640) and the
  in-script diagnostic prefix are all the resolved path;
- program face: open_shell_script replaces filename with the PATH
  find (shell.c:1595-1597) and push_source records it
  (shell.c:1640), while dollar_vars[0] keeps the spelled name
  (shell.c:1613).

A word carrying a slash is never PATH-searched (findcmd.c:385) and
keeps its typed spelling on both faces.

execute_enoexec_shell_script now seeds the reader name from the
find_user_command result (program) for slash-less words; in
main.rs run_script_file_with_init, when find_script_on_path
supplies the file, __RUBASH_SCRIPT_NAME (the reader-name carrier
seeding BASH_SOURCE and diagnostic names) takes the found name
while BASH_ARGV0 keeps the spelled name.

Pins: tests/issue2302_bash_source_bare_name_regressions.rs —
command-face bare/direct/diagnostic cells, program-face
bare/diagnostic cells, slash-spelling and not-in-PATH controls.
Byte-verified against GNU bash 5.3.20.

Refs #2302
… resolved-path prefix (Refs #2302)

The pin asserted the bare command name; GNU bash 5.3.20 prints the
PATH-resolved path actually opened on both the -c and program faces
(verified with script-file probes). The #2302 fix made rubash match
GNU; the pin had enshrined the pre-fix deviation.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Collector adjudication of the CI red (Compatibility CLI tests): the single failure, fd_redirects::c_external_command_reports_write_error_for_closed_stdout, is a WRONG PIN, not a regression. Script-file probes against GNU bash 5.3.20 show GNU prints the PATH-resolved path actually opened (<abs path>/emitout: line 1: echo: write error: Bad file descriptor) on both the -c and program faces; master printed the bare name (the deviation the pin had enshrined), and this PR's #2302 fix makes rubash match GNU byte-for-byte. The pin is corrected in 5cf2466 (tests-only; expectation now builds the resolved path). Full local cli_tests comparison vs master: identical failure sets (10 stock VM reds) apart from that pin. Remaining gates: this PR's CI re-run on 5cf2466 + the collector's already-green pin/lib batches (issue2304 5/5, issue2302 7/7, lib 985/985).

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