Repository navigation
fix(test): resolve -ef/-nt/-ot fd-alias operands through the fd table (Refs #3432) - #3446
Merged
Merged
Conversation
… (Refs #3432) GNU: test.c:330-352 filecomp stats each operand through sh_stat (lib/sh/eaccess.c:80), which fstats the descriptor the process holds for /dev/fd/N; on Linux a plain stat of /proc/self/fd/N lands on the bound file because the shell's OS fd N IS user fd N. Rubash's fd table is virtual: the process permanently holds its cwd anchor at OS fd 3, so user fd 3's file lands on the next free OS fd and every higher user fd cascades — a plain stat() of /proc/self/fd/N read OS fd N, the PREVIOUS user fd's file (the anchor directory for N=3). The sync now also mints __RUBASH_FD_STAT_<fd> (fstat(2) on the entry's kernel handle: dev, inode, mtime sec/nsec, unix only) beside the TARGET/ACCESS facts, and the binary file operators resolve an fd-alias operand through the marks (STAT, then TARGET path, then the literal path). The [[ ]] binary arm never synced the marks at all — it does now, mirroring the unary arm. A dup shares the source's open file description, so its STAT mark travels with it (overlay DupOf arm); an overlay supersedes the entry's fact, so a stale STAT mark must not survive it. Regression pin: tests/issue3432_test_fd_identity.rs (6 tests: -ef, -nt/-ot, [ ]/[ [[ ]] forms, dup/pipe/deleted faces).
Member
Author
复核:PASS(队长复核轮次 2,头
|
caomengxuan666
marked this pull request as ready for review
November 14, 2026 01:08
This was referenced Nov 14, 2026
[bug] test -ef/-nt/-ot resolve /proc/self/fd/N and /dev/fd/N to the wrong file (off by one fd)
#3432
Closed
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.
Refs #3432.
UNVERIFIED-BY-CAPTAIN — 队长复核未开始,CI 为首验。
修复
test -ef/-nt/-ot对/proc/self/fd/N与/dev/fd/N操作数错位一个 fd(fd N 被当作 fd N−1 的文件,fd 3 落回 proc 条目自身元数据)。根因:rubash 的 fd 表是虚拟的——进程常驻 cwd 锚点占 OS fd 3,用户 fd 3 的文件落在下一个空闲 OS fd,逐级错位;二元文件操作符直接 stat 字面路径,读到的是 OS fd N(即上一个用户 fd 的文件)。修法:同步时在 TARGET/ACCESS 事实旁加铸
__RUBASH_FD_STAT_<fd>标记(对条目内核句柄 fstat(2):dev、inode、mtime 秒/纳秒,仅 unix),二元操作符按 STAT → TARGET 路径 → 字面路径的阶梯解析 fd 别名操作数;[[ ]]二元臂此前从不同步标记,现与一元臂同契约;dup 共享源的打开文件描述,故其 STAT 标记随 DupOf 臂传递;overlay 取代条目事实时清除陈旧 STAT 标记。GNU 依据:
test.c:330-352filecomp 经sh_stat(lib/sh/eaccess.c:80,对/dev/fd/N直接 fstat 持有描述符)取 stat;-ef为same_file(general.c:673,比 (st_dev, st_ino)),-nt/-ot比 stat mtime。回归钉
tests/issue3432_test_fd_identity.rs(6 tests:-ef形、-nt/-ot形、test/[ ]/[[ ]]三形态、dup/管道/已删文件面;仅 unix;断言均为退出码)。本 PR 删除了什么
无删除。仅新增:
FD_STAT_PREFIX常量、fd_stat_parts/stat_mtime_nsec(fd/unix.rs)、fd_alias_stat/stat_mark_time/fd_alias_target_path/operand_identity(test.rs 内)及[[ ]]二元臂的标记同步。write_buffered_builtin_output_ordered等既有 API 未动。验证(车道自测,待队长复核)
cargo fmt --check本地干净;marker-lint 全树与 UTF-8 卫生、RUSTFLAGS="-D warnings" 全靶复核、cross-target(darwin + armv7-android)check:复核轮核验。