Skip to content

[bug] 进程替换作为外部命令参数时 /dev/fd/N 指向不存在的 fd #438

Closed

Description

@caomengxuan666

复现

diff <(echo a) <(echo a)
# /usr/bin/diff: /dev/fd/63: No such file or directory
# /usr/bin/diff: /dev/fd/62: No such file or directory

注意对比:cat < <(echo hi)(进程替换作为 redirection target)可用;mapfile -t m < <(...)(builtin)可用。只有把 <(...) 当作参数传给外部命令的路径坏了。

strace 定位

  • niu 把「/dev/fd/63」「/dev/fd/62」写进 diff 的 argv,随后 execve;
  • 但全程没有 pipe2() 创建对应读端,也没有把管道 fd dup 进子进程;父进程只 write(5, "a\n"),关闭 5,然后直接 exec。
  • 子进程 diff 打开 /dev/fd/63、/dev/fd/62 均 ENOENT。

即 niu 登记了进程替换的 fd 编号却没把管道读端传递下去(或传递前被关闭)。

环境: Niubash v1.3.3 / rubash 646237e, Linux x86_64。可复现脚本 probe.sh 中与 procsub 相关条目。

Activity

  1. added
    P2-medium
    on Oct 9, 2026
  2. added a commit that references this issue on Oct 9, 2026
    d137b64
  3. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Still broken on niu 1.4.4 (rubash 1b14a3d) vs GNU bash 5.3.20, Termux — requesting reopen.

    echo a | tee >(cat) > /dev/null
    # bash: prints `a`, rc=0
    # niu:  `tee: /dev/fd/63: No such file or directory`, rc=1 (3/3 stable)

    Same with outer pipe (echo a3 | tee >(cat >&2) 2>&1 | head -2 → bash a3/a3, niu error + single a3). The write-side fd path is never opened in the external child. Siblings #1219/#1220/#1221 assume the procsub runs; here it never starts for external consumers.

  4. caomengxuan666 commented on Oct 24, 2026

    @caomengxuan666
    MemberAuthor

    Verified fixed on current master (7d7818a) in the round-3 recheck: /dev/fd/N handling for diff/cat/wc identical to GNU bash 5.3.20. Closing as already fixed.

  5. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-medium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions