Skip to content

[fd] read 自身输出重定向 0>file 仍静默丢 EBADF 诊断(#3773 c4 残面) #3774

Closed

Description

@caomengxuan666

缺陷

read x 0>out2.txt 静默失败:rc 1、x 为空、stderr 为空、out2.txt 为空。GNU 报诊断:

read: 0: read error: Bad file descriptor

GNU 锚点:builtins/read.def:911(hard read(2) 失败 → builtin_error,不是 EOF)。

根因

execute_read 从不把命令自身的重定向绑进 fd 表(src/executor/builtin_redirects.rs 文档明言)。0>out2.txt 只做了开文件的副作用,fd 0 的 ambient 读臂(进程 stdin)仍在表里;读 funnel 读到 ambient 端点上的 EOF,静默收尾。#3773 的修法(read_io.rs 内 is_open && !is_open_for_read 记 read_error)看不见此次写-only 状态。

证据(X299 实测,#3773 头 ee11284)

  • head 腿 7/8,唯一红格 issue_own_output_redirect_diagnoses;base 腿 fail-first 5/8,c4 红在其中,钉非空洞。
  • 有界对照:p1 exec 0>out.txt; read x 报诊断(test: pin read on write-only fd 0 must diagnose EBADF (Refs #3770) #3773 修法有效);p2 read x 0>out2.txt 仍静默——诊断不是写错地方,是根本没产生。
  • 注意:此红在 CI 上不可见——Rust tests 任务只跑精选 nextest 表,不含新钉茎 tests/issue3770_read_writeonly_fd0.rs。

修复方向(未实施)

在 read funnel 内查命令自身的输出绑定——own_input_binding_scan(src/executor/read_redirected_fd.rs:461,#2305,redir.c:237 顺序胜者)的镜像:若胜出的 fd-0 绑定是输出类(Output/Append/ClobberOutput),该描述符即写-only,记 read_error 后返回 None。需处理顺序(0>o 0<i 输入胜出可读;反之 EBADF)与 -u N 同形。改动面只在 read funnel,不动 execute_read 不绑表的既定设计。

归宿

补进 #3773 同分支(钉 c4 格已在 tests/issue3770_read_writeonly_fd0.rs 内,当前 head 上红)或另开 follow-up PR。#3773 合入前此格须先绿,并以 X299 腿核验(CI 看不见)。

Refs #3770, Refs #3773.

Activity

  1. added this to the 1.5.1 milestone on Nov 16, 2026
  2. added
    bug
    on Nov 16, 2026
  3. added
    gnu-baseline
    area:fd
    area:builtins
    on Nov 16, 2026
  4. added a commit that references this issue on Nov 17, 2026
    c239f91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:builtinsarea:fdbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions