Skip to content

Special paths: complementary-end opens of pipe endpoints need an appendable byte-channel endpoint kind #2385

Closed

Description

@caomengxuan666

Residual class from the #2359 engine special-paths wave (PR #2383, REPORT ~/workspace/fix-2359-dev-paths/REPORT.md). GNU: opening a pipe read end's /proc/self/fd/N in write mode materializes the pipe's other end in the kernel (probes s02, u01, u02 in the wave corpus). rubash materializes procsub streams as in-memory TextInput (fd_table.rs:14, built whole at bind, no appendable channel), inherits stdin as a direction-locked virtual endpoint, and no OutputTarget variant can carry such a write channel; external stages have none at all. Closing this needs a new appendable byte-channel endpoint kind in the fd model — an engine design item, deliberately not hacked into the #2359 wave. Destination: post-1.5.0 engine design wave; when picked up, the s02/u01/u02 probe shapes become its pins.

Activity

  1. added
    enhancement
    gnu-baseline
    on Oct 31, 2026
  2. caomengxuan666 commented on Nov 1, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(PR #2470,merge 7a664134)。

    GNU 合同

    写模式打开 fd 别名拼写走 redir.c 的 do_redirections 对 magic link 的普通 open()(redir_open,redir.c:725):HAVE_DEV_FD 构建下把名字附到描述符的流上的是内核而非 bash——管道的情形下,这个附着就是管道的另一端。bash 没有管道专用代码;「物化互补端」是内核对 pipe: inode 的 open() 语义。

    实测面(脚本文件探针):echo x > /dev/fd/3(fd 3 为管道读端)字节按 FIFO 写序汇入读端所服务的同一流;exec 4> /dev/fd/3 持久绑定、后写追加;4<> 双向;> 与 >> 同写(管道无偏移);set -C 不拦管道链接;关闭/未开的源 fd 在重定向时 ENOENT 报错(master 本已一致);dup 不是打开——echo x >&3 对读端仍 EBADF(master 本已一致、不得回归);读游标不因追加移动;读端关闭后写入仍静默成功(procsub 记账保流身份,无 EPIPE 面);外部子进程对真管道的互补写双向可达。

    修法(端点种类机制,非路径名特判)

    新增可追加字节通道端点:内存通道 FdWriteEndpoint::PipeChannel(Rc<RefCell<TextInput>>)——与源读端同一 Rc 分配,写追加队尾、读游标不动;内核管道则走 fd::complementary_write_file 在 unix 上对 /proc/self/fd/{handle} 做 O_WRONLY 魔法打开(正是 GNU open() 的动作),包成既有 File 端点。单一解析器 fd_alias_complementary_write_endpoint 只在写模式拼写打开且既有臂全部拒绝后被咨询,按源读端点种类(非 fd 编号)解析。消费方:ordered walk 的 OutputTarget::PipeChannel、fd 表绑定器(复合/条件)、N<> 别名臂的写方向、write_dev_stdio_redirect_output、外部阶段的捕获管道排流。无公开 API 变更(全部 pub(crate),api-ledger 无 fd 模型符号),niu 侧零改动。顺带以机制修三处:ordered walk 的 Closed 种子让 dup 捷径抢答拼写目标、exec walk 的拼写目标助手为 >/<> 复制读端、外部目标链缺拼写互补分支(子字节曾漏到壳真 stdout 且状态 0)。

    Windows 边界(设计内):内核管道手柄在 Windows 上无互补打开 API,解析器 decline、保持 EBADF 现状;虚拟流(procsub/herestring)走内存通道载体、在 Windows 同样获得互补端。

    验证

    顺带定性

    #2256 目标的 issue2256_numbered_bind_then_dup_reads_fresh 在 master 上确定红(主会话在 master 树与本 PR 树各复跑一致、本 diff 不触输入路径)——已另行立案 #2479。

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

Metadata

Metadata

Labels

enhancementgnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions