Skip to content

fix(test): resolve -ef/-nt/-ot fd-alias operands through the fd table (Refs #3432) - #3446

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3432-test-fd-off-by-one
Nov 14, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3432-test-fd-off-by-one

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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-352 filecomp 经 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 未动。

验证(车道自测,待队长复核)

  • 钉 fail-first(base 顶起驱动)与 head 全绿、lib 双边名集、相邻 stems、GNU 三方探针:见 REPORT(box 腿进行中,交付时补齐)。
  • cargo fmt --check 本地干净;marker-lint 全树与 UTF-8 卫生、RUSTFLAGS="-D warnings" 全靶复核、cross-target(darwin + armv7-android)check:复核轮核验。

… (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).
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核:PASS(队长复核轮次 2,头 6d44bc09)

本 PR 产品面已全核,准予合入。逐项证据(复核员实跑 + 队长亲核):

  • 钉双边:头 issue3432_test_fd_identity 6/6(两轮);基底 + 钉覆盖 2/4 fail-first(红名与预期一致)。
  • GNU 对照:种子 r108a 头 10/10 == GNU 10/10;r108e 头 17/17 == GNU 17/17;GNU 锚点 test.c:318-352、eaccess.c:80、general.c:673 逐行亲核;st_mtime_nsec 取自锁定版 libc 0.2.186 crate 源码核对。
  • 相邻茎:7 茎 49 测全绿。
  • lib 双边:头 1246/0/4、基底 1246/0/4,失败名集差 ∅。
  • -D warnings:1319 次被标记 rustc 调用(1319 个不同 crate)零产品警告;lib/bins 检查下未编译的 146 个文件均为测试文件,本 PR 钉文件不在其中(已编译)。
  • 卫生:fmt / marker-lint / UTF-8 三项全绿;交集 ∅(对 e50cea96;合入轮对活尖再算)。
  • 终头 CI(runs 43244474832 / 43244474845):10 pass + 1 skipping,含 darwin 与 linux/android 跨靶腿全绿。

非阻塞小疵(合入后顺手修,不必本轮):conditional.rs 注释引「sh_stataccess … eaccess.c:116」,该函数实在 eaccess.c:136,仅注释行号。

正文 Refs-only;合入后 #3432 仍 OPEN,由队长手动关单。X299 Windows 靶腿记 Owed(车道钥匙待装),本 PR 为平台中立面、CI 的 Windows 编译检查已过,不挡合入。

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