Skip to content

fix(executor,builtins): #872 fd-table nits — move_to_high_fd comment + single-source fd defaults + drop dead field - #885

Merged
caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-872-fd-nits
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-872-fd-nits

Conversation

@arookieofc

Copy link
Copy Markdown
Member

What

Closes #872. Three zero-behavior cleanups from PR #870's CR round:

  1. 坐标勘误: compound_exec.rs / external_setup.rs described move_to_high_fd (general.c:681) as fcntl F_DUPFD-backed. It is actually dup2-backed: GNU scans downward from maxfd-1 with fcntl(F_GETFD) and dup2()s into the first free slot. F_DUPFD is the other mechanism (redir.c:942) backing {var} allocation. Comments now describe the real mechanism and note the low-first fallback is a pre-existing simplification of GNU's high-side scan.
  2. 双点钉死: the default RLIMIT_NOFILE pair (soft 10240 / hard 1048576) lived in both fd_table.rs and ulimit.rs. ulimit::default_for now reads FdTable::DEFAULT_OPEN_FILES_SOFT_LIMIT / UNLIMITED_OPEN_FILES_CEILING so the reporting side and allocator ceiling share one declaration point.
  3. 死字段: FdTable::next_dynamic_fd was write-only (assigned at init and after each allocation, never read). Field and writes removed.

Verification

  • cargo build clean; cargo fmt --check clean.
  • cargo test --test issue773_fd_table_capacity_regressions --test issue844_848_popd_pushd_readonly_range_regressions: 19/19 green.
  • cargo clippy --lib: same 5 pre-existing deny-lints as master (uname.rs never-loops, trap_exec.rs almost-swap, conditional.rs eq_op + invalid_regex, process_substitution.rs almost-swap) — unchanged by this PR.

Zero behavior change.

…correction, single-source fd default pair, drop write-only next_dynamic_fd

- compound_exec.rs / external_setup.rs: move_to_high_fd (general.c:681) is
  dup2-backed (F_GETFD scan + dup2), not fcntl F_DUPFD; F_DUPFD is the
  redir.c:942 mechanism for {var} allocation. Rewrite the comments to
  describe the real GNU mechanism and note that the low-first fallback is
  a pre-existing simplification of GNU's high-side scan.
- fd_table.rs / ulimit.rs: the default RLIMIT_NOFILE pair (soft 10240 /
  hard 1048576) was hardcoded in two places; ulimit::default_for now reads
  FdTable::DEFAULT_OPEN_FILES_SOFT_LIMIT / UNLIMITED_OPEN_FILES_CEILING so
  the reporting side and allocator ceiling share one source (rubash#872).
- fd_table.rs: next_dynamic_fd was write-only (assigned, never read);
  drop the field and its updates.

Zero behavior change; fd + ulimit family regressions green.
@github-actions

Copy link
Copy Markdown
Contributor

欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。

@caomengxuan666

Copy link
Copy Markdown
Member

评审结论:APPROVE ✅(#872 fd-table nits 清包 — 独立评审,基于自建 worktree @ a1d4655,逐项实测)

1. 三项 nit 逐项核对 — 全部落实

① move_to_high_fd 坐标/机制注释(compound_exec.rs / external_setup.rs)— 准确。
对照 submodule third_party/bash @ b460816(bash-5.3 patch 15)实读:

  • general.c:681 确为 move_to_high_fd (int fd, int check_new, int maxfd) 函数签名行;
  • general.c:696-698:for (nfds--; check_new && nfds > 3; nfds--) if (fcntl (nfds, F_GETFD, &ignore) == -1) break; — 从 maxfd-1 向下 F_GETFD 扫描空闲槽;
  • general.c:700:if (nfds > 3 && fd != nfds && (script_fd = dup2 (fd, nfds)) != -1) — dup2 移动,与背景所述 ":700 dup2" 完全一致。旧注释的 "F_DUPFD consumer" 误标已被正确改写。
  • 对照面 redir.c:942:redirector = fcntl (fd, F_DUPFD, SHELL_FD_BASE);(REDIR_VARASSIGN 分支,即 {var} 分配)— 新注释的机制对比成立。信息性备注(不阻塞):F_GETFD 下扫仅在 check_new != 0 时执行;本 PR 两处 fallback 场景(高位 fd 被占)正对应 check_new=1 语义,注释成立。

② fd 默认对双点钉死收敛 — 落实。
FdTable::DEFAULT_OPEN_FILES_SOFT_LIMIT = 10240 / UNLIMITED_OPEN_FILES_CEILING = 1_048_576(fd_table.rs:190/:196,#870 已引入,pub(crate))为单一事实源;ulimit.rs 的 'n' 分支改为引用两常量(as u64 无损),mod.rs 将 fd_table 提为 pub(crate)(纯可见性)。运行时等价由回归 emulated_ulimit_defaults_match_oracle 钉死(10240\n1048576\n,本机复跑通过),汇报侧与分配器上限不再可漂移。

③ next_dynamic_fd 死字段 — 删除正确。
master 上全仓恰好 3 处引用(fd_table.rs:118 声明 / :148 初始化 / :243 写入),零读取;PR 三处全删且全仓无残留引用。该写入不参与返回值(Some(candidate) 与其无关),删除可证无行为影响;FdTable 无 Debug 快照类断言依赖字段形状。

2. 行为零变更 — 证实

5 文件 diff 逐一归类:compound_exec.rs / external_setup.rs 纯注释改写(代码行未动);ulimit.rs 同值常量替换;fd_table.rs 死字段删除;mod.rs 可见性。无任何逻辑变更。
fd 家族回归本机自跑(PR worktree 构建):fd_table lib 单测 4/4、#773 套件 7/7(含 #482 dup_semantics_survive_the_raised_table、1200 分配 repro)、issue279 4/4、cli dup 过滤 5/5(含 coproc stdin dup、bg-dup 共享 offset、dev/fd dup chain)— 20/20 全绿,无回退。

3. 越界审计与已合并内容冲突面 — 干净

git diff origin/master...pr-885 --name-only 恰为声明的 5 个文件,零越界。PR 分叉点 2b98675 已包含 #876 合并(f5701503)与 #877 合并(41bfdd36,即 #875 议题),三议题同区改动均在 PR 祖先内;另对最新 origin/master(78952f58,仅前进一个 docs-only #886)做 git merge-tree 预演:0 冲突,GitHub 侧 MERGEABLE 一致。

4. GPL / fmt / warnings / 进程卫生 — 通过

  • GPL:无 third_party / LICENSE 改动;新增注释为原创表述 + file:line 事实引用,无 C 源复制。
  • fmt:4 个改动叶文件 rustfmt 单文件检查全部 CLEAN;executor/mod.rs 在本地 rustfmt 1.10 下报的漂移在 origin/master 同文件上完全复现(129/222 两处,仓库级既有工具链漂移),非本 PR 引入。
  • -D warnings:本地 clippy 1.99 下 master 与 PR 树错误集逐条一致,差异仅为注释增删行导致的 +4(compound_exec)/+5(external_setup)/−3(fd_table)行号平移 — 本 PR 引入 0 条新 lint;CI(权威门)全绿。
  • 测试收尾已查无 stuck rubash.exe;评审自身遗留 cargo 包装进程按 PID 定点清理(白名单内)。

结论

APPROVE — 三项 nit 全部按 #872 意图落实且注释与 bash-5.3 源码逐行吻合,行为零变更获 20 例 fd 回归实证,越界/冲突面/GPL/进程卫生全部干净。无阻塞项,无新增 nit。不代合并,合并交由维护者。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants