Skip to content

WIP: fix(executor): bind the read-write pair for a child script's <> fd 0 - #2267

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2261-childscript-rw
Oct 30, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2261-childscript-rw

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: 子脚本 <> fd-0 安装改绑读端点对(#2249 函数面姊妹面)

Refs #2261

定性

execute_direct_shell_script(external_finish.rs)的 file_stdin 安装对一切文件目标都绑 FileFd::open_read——./child.sh <>f.txt 时子脚本只拿到 fd 0 的读端点,体内 echo x >&0 报 Bad file descriptor。GNU 的 <> 是 r_input_output(make_cmd.c:682-683 给 O_RDWR|O_CREAT,redir.c:725 redir_open 执行打开):单一描述符双向、共享偏移。

基线形状补充(读码定性):目标已存在时只读安装获胜(issue 形状);目标不存在时 open_read 失败、落到 function_call_stdin 的 <> 臂以副作用绑 pair(binding 在此调用点被丢弃),该形状可能已偶然通;<> 目录时 open_read 在 Unix 可成功、子脚本误跑(GNU 应 EISDIR 不跑)。

修复(单文件 +39/−2)

回归钉

tests/issue2261_child_script_readwrite_fd0_regressions.rs 9 条(写落盘 / 共享偏移判别格 / O_CREAT 创建 / 父 fd 0 恢复 / cd 锚写面 / 目录 EISDIR / 编号 3<> 对照 / 普通 < 两对照),期望全部按 GNU bash 5.3.20 oracle 脚本文件实测(探针 probeP1–P10 + expected/ 在簇工作区)。相邻面 issue2249 / issue2240 已在钉头列明不回退要求。<> /dev/null 仅作探针观察(P8),未落钉,理由见簇 REPORT。

验证分栏(编译配给制)

  • 已做(本地):cargo check --lib --tests exit 0(本簇两文件零警告);逐文件 rustfmt clean;CR=0;GNU oracle 探针全跑存档。
  • 待主会话批量补验:本测试目标实跑、probes/run-probes.sh 对修复后二进制实跑(含 P8 观察格)、相邻目标 issue2249/issue2240/redirect_fd/fd_var 复跑;全量门走本 PR CI。

caomengxuan666 and others added 2 commits October 30, 2026 17:21
Refs #2261.

execute_direct_shell_script's fd-0 install bound FileFd::open_read
for every file target, so a child script run with `<>file` got only
the read endpoint of fd 0 and `echo x >&0` inside the child failed
Bad file descriptor. GNU's `<>` is r_input_output (make_cmd.c:682-683
— O_RDWR|O_CREAT; redir.c:725 redir_open): one descriptor serving
both directions over one open file description.

Mirror the function-call face (function_call_stdin, rubash#2249):
for a ReadWrite redirect the install now binds
FileFd::open_readwrite_pair on the same #2240 operand ladder and
applies the fd-0 output env bookkeeping (fd_output_key(0), mirroring
save_and_apply_fd0_readwrite_env). The undo is the site's existing
whole fd-table / env save-restore around the child run. A failed
pair open and net targets keep the function_call_stdin fall-through,
as plain `<` does.

Pins: tests/issue2261_child_script_readwrite_fd0_regressions.rs (9).
Expectations measured against GNU bash 5.3.20 (script-file probes
probeP1-probeP10 in the cluster workdir).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 17:33
@caomengxuan666
caomengxuan666 merged commit fee7a9d into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2261-childscript-rw branch November 2, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant