kernel: handle AT_EMPTY_PATH in fstatat so File#stat on an fd works#865
Open
brandonpayton wants to merge 1 commit into
Open
kernel: handle AT_EMPTY_PATH in fstatat so File#stat on an fd works#865brandonpayton wants to merge 1 commit into
brandonpayton wants to merge 1 commit into
Conversation
`fstatat(fd, "", AT_EMPTY_PATH)` must stat the open fd itself, equivalent to `fstat(fd)`. glibc/musl's `fstat` and Ruby's `File#stat`/`IO#stat` route through this form. Previously the empty path fell through to `resolve_at_path`, which returns ENOTDIR when dirfd is a non-directory fd — so `File#stat` on any regular-file fd failed with Errno::ENOTDIR. This broke Homebrew inside Kandelo: `brew`'s download-lock code opens the lock file (RDWR|CREAT) and calls `File#stat` on the fd, which raised ENOTDIR and aborted every `brew install`/download before fetching. Detect AT_EMPTY_PATH with an empty path and a real dirfd up front and delegate to sys_fstat. `sys_statx` already delegates to `sys_fstatat`, so statx-based callers are fixed too. Pure kernel behavior; no ABI change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Purpose
fstatat(fd, "", AT_EMPTY_PATH)must stat the open fd itself — equivalent tofstat(fd). glibc/musl'sfstatand Ruby'sFile#stat/IO#statroute through this form. The kernel did not recognizeAT_EMPTY_PATH, so the empty path fell through toresolve_at_path, which returnsENOTDIRwhendirfdis a non-directory fd. As a result,File#staton any regular-file fd failed withErrno::ENOTDIR.This is a real POSIX gap, surfaced by running upstream Homebrew inside Kandelo:
brew's download-lock code opens the lock file (RDWR|CREAT) and callsFile#staton the resulting fd. That raisedENOTDIRand aborted everybrew install/ download before fetching anything.Fix
Detect
AT_EMPTY_PATHwith an empty path and a realdirfdup front insys_fstatatand delegate tosys_fstat.sys_statxalready delegates tosys_fstatat, sostatx-based callers (glibc's modernfstat) are fixed by the same change.Linux semantics preserved: without
AT_EMPTY_PATH, an empty path against a file fd still returnsENOTDIR.Validation
test_fstatat_empty_path_on_file: empty-path stat on a regular-file fd and on a pipe fd both succeed and match plainfstat; without the flag, empty path still yieldsENOTDIR.cargo test -p kandelo --target aarch64-apple-darwin --lib→ all pass (964 on main + this test).scripts/check-abi-version.sh: snapshot in sync — no ABI change (pure kernel behavior).brew installinside Kandelo advances past the download-lockFile#statand reaches the fetch stage (previously it aborted at lock acquisition).🤖 Generated with Claude Code