Skip to content

/dev/fd/N 打开普通文件应 fresh open(偏移 0),现 alias 层全域 dup 共享偏移 #2256

Closed

Description

@caomengxuan666

分歧(#2235 簇发现 1,fix-fd-next-2234-2235 REPORT「Discoveries」;存量、代码库级)

/dev/fd/N 打开普通文件时 GNU 是重新 open(偏移 0):

exec 6<seed; cat /dev/fd/6; cat /dev/fd/6    # GNU: seed 内容打印两次

rubash 的 #1963 alias 层是全域 dup/共享偏移模型(open_fd_read_endpoint,shell_options.rs:627-631 有记):两次 cat 只打印一次。master 实证:操作数形与 fd-0 alias 形同差。

定性:这是 alias 层的模型决策,不是单点 bug——若改 GNU 的 fresh-open 面,全部 alias 消费者必须一起动(管道不可重开、dup 仍是唯一模型,须按端点类型分流)。修复归宿由主会话排期(跨消费者同批动),本条先立账防丢;各 binder 不得各自特判。

Activity

  1. added
    bug
    gnu-baseline
    P2-medium
    area:fd
    on Oct 30, 2026
  2. added this to the 1.5.0 milestone on Oct 30, 2026
  3. added a commit that references this issue on Oct 30, 2026
  4. caomengxuan666 commented on Oct 30, 2026

    @caomengxuan666
    MemberAuthor

    Closed by PR #2275 (merge commit 01ecad1b191cd09e0749baef4e44bdad25a23d3c), two waves:

    • Wave 1 (bc237c5): /dev/fd/N opens of regular files now fresh-open instead of alias-dup'ing the shared offset, across the redirect / operand / builtin faces routed through FileFd::reopens_fresh / fd_alias_reopen_path.
    • Wave 2 (26c3fea): the eight never-covered faces found at wave-1 harvest (noclobber+truncate via the ordered walk's resolver gate, builtin flush fresh-open, read spelling-vs-dup split, resolver-first source face, fd-0 operand fresh for regular-file stdin, own-input binding fresh FileFd).

    Verification: CI 11/11 green on the composed head 0d253a5a on the merged head; collector's scrubbed-fd batch on the composed tree — issue2256 pins 25/25, issue2249 pins 9/9, controls issue1963 6/6, issue2235 11/11, issue2238 8/8, issue2265 11/11. Every pin oracle-checked against GNU bash 5.3.20; no pin was modified in either wave.

    Note: wave 2 also fixes a pre-existing master defect in stdin_string_for_command (a function's cat <&0 stole the caller's pipeline spool despite the <> rebind) through the same File-endpoint guard as function_stdin_is_command_source — master's red issue2249 interaction pin turns green with this merge. #2249 itself stays closed; this is recorded here because the fix rode this PR.

    Residuals dispositioned (NOT part of this closure):

    1. Wave-1 Discovery ② — pipeline-stage fd-0 alias binds still dup for spelling targets. Deliberately untouched here: the resolver is ready, but the stage faces belong with the reopened 管道 stage 自身重定向不被应用(cat 3<seed <&3 | wc -c 输出 0) #2255 stage work (§8 ≥3-stage stage-0 delivery) in the fd audit ledger.
    2. Split-endpoint corner and the Windows fd-0 operand-drain observations from the wave-2 report — audit ledger, no reproducer elevates them to a filing.
    3. External-command stdio plan mis-serving read-bound alias output (exec 6<seed; /bin/echo X > /dev/fd/6) is filed separately as 外部命令 stdio 计划对只读别名输出误服(/bin/echo X > /dev/fd/6 写穿到真实 stdout) #2285 — that is the external face only; the in-process faces are fixed here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-mediumarea:fdbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions