Skip to content

[bug] P0 source/exec 重定向到常规文件时函数型 comsub 输出泄漏捕获为空(bash-it 加载破坏);comsub 内 &+wait 不捕获(nvm ls 缺行) #161

Closed

Description

@caomengxuan666

环境

rubash 096a839;对照 WSL GNU Bash 5.3.0;来源=target-ecosys3/REPORT.md N2/N3(10 变体矩阵探针 probes/src-matrix.sh)。

N2(P0):source/exec 重定向到常规文件 stdout 时,函数型 comsub 输出泄漏、捕获为空

10 变体矩阵钉死的边界——漏:source f > file、. f > file、{ source; } > file、exec > file 后 source、嵌套 -c 内 source;不漏:管道 stdout、无 source、纯内建 comsub。即"source 的重定向目标为常规文件"这一组合下,source 体内函数里的 $(...) 输出走漏且变量拿空。

真实破坏:bash-it 完整加载破坏(alias reload_*=''、COMMAND_DURATION_START_SECONDS 空且裸 epoch 数字写入日志、composure cite 级联失败)。

GNU 锚点:subst.c:7143 command_substitute()——comsub 捕获管道与外围重定向共存时的 fd 语义。

N3(P1):comsub 内 &+wait 输出不捕获

OUT="$(for…; do fn & done; wait)" → 输出泄漏到终端且 OUT 为空。疑似与 N2 同一所有者(comsub 捕获路径对后台/重定向组合的 fd 处理)。真实破坏:nvm nvm ls 的默认别名行缺失。

期望

两个形态下 comsub 捕获与 GNU 一致(输出不泄漏、变量拿到完整内容)。

Activity

  1. added
    bug
    on Sep 26, 2026
  2. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    N2 已修复(分支 wt/b161-csub,commit 12d11807,基线 8f89767)

    根因(两层,同一族)

    1. run_function_command_substitution 缺少 comsub 的 fd-1 改绑(src/executor/embedded_mutations.rs:1646)。该快捷路径在调用方自己的 executor 上执行函数体,没有表达 GNU comsub 子进程的 fd 布局:GNU subst.c:7306-7313 command_substitute 在子进程里 dup2(fildes[1], 1) —— 捕获管道无条件替换 fd 1,与父 shell 当前 fd 1 绑定(文件/管道/tty)无关;fd 2 保持继承(subst.c:7149)。修复:在 execute_function 外加与 command_list_substitution_output_typed(Q16 修复)相同的 fd-1 → Stdout endpoint 括号改绑 + 恢复。
    2. compound/source 重定向文本拼接误注入函数定义命令(src/executor/support_names.rs apply_stdout_append_redirect)。source f > file 把注入的 >>file 拼到 sourced AST 的每个命令上,包括 f() {...} 定义行;define_function(function_calls.rs:92-105)把它持久化为 function_definition_redirects,execute_function(:173-187)此后每次调用都重新应用 —— 包括 comsub 内的调用,把函数 stdout 拉出捕获管道写进外层文件。GNU execute_cmd.c execute_function 只应用定义文本里写的重定向:{ f() { echo x; }; } >g 后 g 为空、之后调用 f 输出到调用方 stdout(WSL GNU 5.3.0 已验证,探针 fndef-group.sh)。修复:注入跳过函数定义节点。

    验证(WSL GNU Bash 5.3.0,LF 脚本双侧落盘逐字节比对)

    • src-matrix.sh 10 变体:全等 → target/issue-suites/results/rubash161/srcmat-{gnu,rub}.out
    • 自建 16 变体矩阵(sink:file/exec 预绑/管道//dev/null × 体:内建/函数/外部/函数进管线 × source/dot/brace group/subshell):15/16 全等 → extmat-{gnu,rub}.out + ext-matrix.sh;唯一例外为下述既有边角(基线二进制同样失败,非本修复回归)
    • true-baseline.sh redir:0 diff;comsub diff 与基线二进制完全一致(新 worktree 副本缺 recho/zecho 包装器,环境性)
    • 四门:build 零新增警告;453 lib 测试全绿;cargo check --tests × x86_64-unknown-linux-gnu、aarch64-apple-darwin 干净;改动文件 rustfmt --check --edition 2021 干净

    N2 残余边角(既有 bug,已最小化,未修)

    函数内执行过一次"带重定向的赋值"后,后续 exec 重定向下嵌套函数 comsub 输出丢失(nest4.sh:GNU 打印 W=[FN-arg],rubash 该行缺失)→ target/issue-suites/results/rubash161/nest4.sh + n4-{gnu,rub}.out。基线 8f89767 二进制同样失败,属同族另一层(assignment-with-redirect 在函数内的状态残留)。

    N3(comsub 内 &+wait)未修,所有者不同

    execute_background_ast_command/resolve_background_stdio(src/executor/compound_exec.rs:299/:546)把后台任务 spawn 为真实 rubash -c 子进程,stdio 走 Inherit=复制进程 OS 句柄(process_std_handle),不是进程内捕获管道;GNU 中后台子进程继承 comsub 子进程的 fd 1=捕获管道,wait 后管道 EOF 才由父端读完。修复需要:捕获活跃时给 bg 子进程 piped stdout 并在 wait/完成路径排水回捕获缓冲(含多子进程顺序语义),是一块独立子系统工作。复现:nvm-bg-fn.sh C 段 → nvm-{gnu,rub}.out。

  3. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    补充(bash-it 完整加载验证,worktree 二进制 12d11807 vs WSL GNU 5.3.0)

    • diff 64 → 34 行(target/issue-suites/results/rubash161/bashit-{gnu,rub}-2.out)。
    • N2 核心症状已消失:alias reload_aliases/completion/plugins='' 空 → 现为完整 source .../reloader.bash ... 体(路径 /mnt/d 与 D:/ 拼写为预期平台差)。
    • 残余(同族未竟部分,与 nest4 边角疑似同层):
      • bash-it show aliases 描述列为空(composure cite 元数据链)
      • bash-it search git 分组输出为空
      • type -t ppm rubash 侧多一行 file(Windows PATH 解析差异,环境性)
      • git fatal/Compare-to-latest 行为 WSL git vs Windows git 差异(环境性)
    • 注意:probe-bashit.sh 首跑曾出现 rubash 在 bash-it search git 处提前退出(rc=1、无 == done ==)——同命令重跑即稳定通过(rc=0),未能复现;若再现建议单独抓取(可能与 head 提前关管后的后续管线有关)。
  4. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    N2(P0 主症状)已在 92294b4 修复:run_function_command_substitution 补上 comsub 的 fd-1 改绑(GNU subst.c:7306-7313 语义,与 Q16 的 AST 路径同型)+ 注入重定向不再持久化到函数定义(GNU execute_function 只应用定义文本重定向)。验收(双侧落盘产物 target/issue-suites/results/rubash161/,captain 复核):src-matrix 10 变体 0 差;16 变体 15/16(唯一未过=既有 nest4 边角→新单);bash-it 完整加载 diff 55→34 行、reload_aliases 恢复完整 source 体。N3(&+wait 后台捕获)经定位确认为不同子系统(后台 spawn 的 Inherit stdio),已拆独立单跟踪——见新开的 N3 单。

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions