Repository navigation
WIP: fd-stdin fact cluster (#2131/#2132/#2101) - #2167
Merged
Merged
Conversation
GNU applies a command's redirections before its builtin runs
(execute_cmd.c, redir.c:767-955 do_redirection_internal), and
test.c:544 unary_test -> lib/sh/eaccess.c:116 sh_stataccess stats
the descriptor as bound for that command. rubash's
sync_fd_alias_facts classified only fd-table entries, but a simple
command's own redirects are staged as payloads, never bound — so
`[ -f /dev/stdin ] < file` answered from the ambient stdin, and a
compound's text-channel (FUNCTION_STDIN mirror) rebind stated no
fact at all (`{ [ -p /dev/stdin ]; } < /dev/null` answered pipe).
- sync_fd_alias_facts gains a scoped form taking the evaluating
command's redirection list: after the entries loop, each
redirected descriptor's fact is stated from its winning redirect
(one FdFactMark classifier shared by every consumer), applied in
list order so a dup copies its source's own winning fact.
- A staged fd-0 mirror records its source's fact in
FD0_MIRROR_FACT (set by bind_command_fd0_input's mirror branch
and the flat-subshell region feed, restored by the bind guard);
the sync lets it supersede only the ambient inherited entry the
mirror itself superseded.
- `[[ ]]` stashes its redirection list on the executor for the
scoped sync (only its fds 1/2 are ever bound).
- The late `[`/`test` dispatch now applies the command's redirects
(apply_no_output_builtin_redirects) before evaluating, like the
other two test entries — GNU's open-first order; without it the
fd-1 target existed only at buffered-emit time.
Regression pins: tests/issue2131_fd_alias_own_redirect_regressions.rs
(8 tests; verified 8/8 red on master sources, 8/8 green here;
issue1902's 8 pins stay green).
Refs #2131
…efault The fd-fact sync's ambient arms answered `p` (pipe) for every non-terminal inherited stdin: with the process's stdin = /dev/null, `[ -p /dev/stdin ]` was true and `[ -c /dev/stdin ]` false. The ambient stdout/stderr sinks carried the same console-or-pipe default (a regular-file stderr answered -p true, -f false, and a `>&2` dup inherited the misclassification). GNU test.c:544 -> lib/sh/eaccess.c:116 sh_stataccess stats the descriptor the process actually holds, so the predicates follow the parent's inode, not a default. - New process_stdio_fact classifies a process stdio handle by the fd layer's own probes: console -> crw, pipe -> prw, socket -> srw (new 's' evaluator class; new unix is_socket_handle twin), disk file -> its referent target (windows: GetFinalPathNameBy- HandleW also covers directory handles), char device -> the null class for /dev/null|zero|full else console class, unix directory -> its /proc/self/fd referent target; anything unclassifiable keeps the historical pipe default. - The InheritedProcessStdin arm and the ambient Stdout/Stderr arms consume it (a live stdout capture stays the pipe it is). Regression pins: tests/issue2132_inherited_stdio_classification_regressions.rs (7 tests across null/file/pipe/directory ambients, ambient stdout/stderr files, the compound-rebind reproducer, and the #2131-mirror guard pins; the 4 ambient-mechanism pins verified red on the pre-fix tree, all 7 green here; issue1902/2131 pins stay green). Refs #2132
…ng fails
GNU redir.c redir_open opens a directory like any file: the child
receives the descriptor, a non-reading command runs fine, and a
reading child fails with its own diagnostic (`cat: -: Is a
directory`, read.def:911 for the builtin). rubash killed the
command at open time on Windows and swallowed the read error
everywhere else.
- Windows fd layer: open_file_read retries a directory with
FILE_FLAG_BACKUP_SEMANTICS (create_file_with_flags); the
executor's std-File input opens (classified SyntheticLink arm +
the open_input_redirect fallthrough) route through the same
retry (open_redirect_input_file). Unix opens directories
natively and is unchanged.
- A compound's fd-0 stream class admits directories, so
`{ ...; } < dir` binds the real descriptor instead of the text
mirror that swallowed the failure at bind time (the read
builtin's EISDIR diagnostic and the external reader's error now
surface; `{ cat; } < dir` was rc 0 silent).
- The text stdin ladder declines a hard read error on an empty
buffer instead of serving it as an empty stream (both the
exec-bound fd-0 arm and the `<&N` dup arm), and
FdTable::read_all_bytes records the first hard error on an
empty drain (the read_file_bytes discipline, rubash#1495); the
emulated cat consults it at both stdin drains and reports
`cat: -: Is a directory` with status 1.
Regression pins: tests/issue2101_directory_stdin_regressions.rs
(6 tests; the 3 Linux-observable defect faces verified red on the
pre-fix tree, all 6 green here; the simple-command faces carry
the Windows open defect and are adjudicated by Windows CI).
Adjacent suites green: issue1902/1968/2029/2030/2042/2053/2057/
2103/2111/1898.
Refs #2101
… widening CI's UTF-8 boundary hygiene gate flagged the three `mark.as_bytes().first() ... as char` widenings the ambient arms used to read a fact's class letter. The marks are engine-minted ASCII, but the gate's review rule is the point: decompose through access_mark_parts, which matches the class byte against the evaluator's alphabet (p/c/d/n/f/s) and never widens. No behavior change; the hygiene script is clean and the #2131/#2132/#2101/ 1902 pins stay green. Refs #2132
caomengxuan666
marked this pull request as ready for review
October 30, 2026 02:54
This was referenced Oct 30, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 30, 2026
…ndle (rubash#2171) After `exec 0<dir`, a child that merely inspected the descriptor (`ls -l /proc/self/fd/0`) invalidated the parent's fd-0 FileFd: the next builtin read reported `Bad file descriptor` where GNU reports the descriptor's own `Is a directory` (read.def:911). Same death for any File endpoint on any fd (an exec-bound regular file on fd 3 died identically). Root cause, in the unix branch of materialize_dev_fd_operands: the attach record (DevOperandMaterialization) owns what it records — its Drop closes every recorded handle once the child exits, like GNU closing the parent's pipe end once the forked child owns its copy. Two of its three arms record fresh, owned handles (a capture-pipe read end, a just-opened procsub file). The File arm recorded the endpoint's OWN handle — the parent's live descriptor — so the record's drop closed the parent's FileFd under it; the fd-table entry survived but pointed at a dead handle. Fix: the File arm attaches a duplicate (crate::fd::duplicate_handle). A dup shares the open file description, offset included, so the child's /proc view and the #1952 shared-offset read face are unchanged (verified: a child reading through the operand behaves byte-identically to GNU before and after); the record now closes only its dup, and the parent's descriptor survives any number of inspecting children. Platform shape: the defect and the fix are unix-branch only. The Windows materialization never hands a child the parent handle — it rewrites the operand to the endpoint's path or a temp file, and its deferred consume step seeks (consume_all_text) rather than closes. The read-side EISDIR shape is #2101/#2167's and is not touched. Collision note: this is the cluster's only hunk in src/executor/dev_fd_operands.rs, which open PR #2156 also edits (its hunks are the drain/finish regions; this one is the unix materialize loop's File arm). The borrowed-handle invariant lives only in this file, so the hunk is minimal and flagged in the PR body for merge sequencing. Pins: tests/issue2171_proc_fd_operand_survival_regressions.rs (4 tests; 3 red on master, 1 guard green both ways). Refs #2171
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fd-fact cluster for the #1902 family's residual faces. One issue per commit. Verified locally against the GNU bash 5.3.20 oracle (script-file probes, byte-compared) and with per-issue regression pins (baseline-red / fix-green recorded per commit); full suite adjudication is this PR's CI.
Commits
[ -f /dev/stdin ] < fileanswered from the ambient binding), and a compound's FUNCTION_STDIN mirror rebind stated no fact ({ [ -p /dev/stdin ]; } < /dev/nullanswered pipe). The sync now states each redirected descriptor's fact from its winning redirect (one shared classifier), a staged mirror records its source's fact inFD0_MIRROR_FACT(bind + region feed set it, the bind guard restores it),[[ ]]hands its redirection list to the sync, and the late[/testdispatch applies the command's redirects before evaluating — GNU's open-first order (execute_cmd.c + redir.c:767-955 do_redirections precede the builtin; test.c:544 → eaccess.c:116 sh_stataccess stats the bound descriptor). Pins:tests/issue2131_fd_alias_own_redirect_regressions.rs, 8/8 red on master → 8/8 green.-ptrue /-cfalse; ambient stdout/stderr files likewise. The three ambient arms now classify the process's real handles (console/pipe/socket/disk-file referent/char class/directory referent; newssocket class in the evaluator). Pins:tests/issue2132_inherited_stdio_classification_regressions.rs, ambient pins red pre-fix → 7/7 green.read_all_bytesrecords the first hard error and the emulated cat reportscat: -: Is a directorywith status 1. Pins:tests/issue2101_directory_stdin_regressions.rs, 3 Linux-observable faces red pre-fix → 6/6 green; the Windows open faces are adjudicated by the Windows CI job here.Adjacent suites green locally (run outside the build slot, fd 9 closed): issue1902 8/8, issue1898 6/6, issue1968 14/14, issue2029 10/10, issue2030 8/8, issue2042 3/3, issue2053 4/4, issue2057 2/2, issue2103 11/11, issue2111 12/12.
Refs #2131
Refs #2132
Refs #2101