Skip to content

fix(executor): output redirects open each target once — umask 0200 no longer fails the redirect (Refs #3828) - #3835

Merged
caomengxuan666 merged 7 commits into
masterfrom
fix/3828-umask-redirect-permission
Nov 17, 2026
Merged

caomengxuan666 merged 7 commits into
masterfrom
fix/3828-umask-redirect-permission

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Refs #3828

根因

当 umask 掩掉 0200 时,输出重定向创建的文件缺 owner-write 位,rubash 误报 Permission denied、数据丢失;单次内核 open 本应成功。

GNU 对每个重定向条目只 open 一次目标(redir.c do_redirections :237 / do_redirection_internal :790 / redir_open :949,fd = redir_open(...); if (fd < 0) return (errno);)。rubash 的 probe-then-bind 在多条路径上把同一目标 open 两次:有序 walk(open_command_output_target)open 后丢弃 File,只记 Path,flush 时按路径重开;exec / group / null-command / external spawn 的 gate 与 bind 各自再 open 一次。已创建的 mode 000/444 文件第二次 open 即 EACCES。

本 PR

  • commit 1(c84db5c6):有序 walk 的 create/append open 即条目的那一次 open——File 以 SharedFile 保留,flush 经该 handle 写,不再按路径重开;新增 File 版 probe 双生子(probe_output_redirect_file / probe_output_redirect_append_file),原 () 版 probe 改为委托,调用方行为不变。FIFO / net / 特殊类目标仍不保留 File。
  • commit 2(5ff2893e):回归钉 tests/issue3828_umask_redirect_permission.rs,13 格(创建/写/append/exec/group/外部命令/<>/控制格),#![cfg(unix)],root 下经 setpriv 以 nobody 跑。
  • commit 3(770ac85f):exec 持久绑定与 compound scope 的输出重定向经 probe 的 open 绑定(set_fd_output_file_from_file,7 处调用点)。
  • commit 4(47994a87,定序):external spawn 的 preflight→spawn 接线(command_output_redirect_fails_with_preopened,fd 1/2 经 adopt_preopened_combined_target 采用 gate 的描述符,fd ≥ 3 经既有 collect_external_fd_delivery preopened 通道);no-output builtins 的 gate/mirror skip-set(pregate 记录真实打开的 plain-file 位置,mirror 跳过已记位置的二次 open;: > f > g 不做 undo-delete,FIFO/net/special 不记录,Input 条目不记录);删重复定义与死代码(见下)。

本 PR 删除了什么

  • trap_exec.rs 中重复的 set_fd_output_file_from_file 定义一处(未提交版签名 (fd, file, target, dynamic),零调用点;保留已提交版 (fd, target, dynamic, file) 及其 7 处调用点)。
  • 未提交的 set_fd_readwrite_file_from_file(零采用点:exec/compound <> 本就是单次 open,mirror 的 <> 用 skip-set 而非 adopt,留着会是 dead_code)。
  • 布尔版 command_output_redirect_fails 包装(唯一调用点已改用 _with_preopened,留着会是 dead_code)。
  • () 版 probe_output_redirect_append(唯一调用点已改用 _file 双生子;其文档注记并入 _file 版)。

余项(未修,见 REPORT)

  • env 腿与 spawn_async_direct(后台/ENOEXEC spawn)不跑 preflight,仍按路径二次 open。
  • pipeline stage:gate 的 preopened 未接线到 stage spawn(apply_external_fd_delivery 传 None),stage 的 fd ≥ 3 delivery 仍按路径 open;routing walk(route_pipeline_stage_streams_inner)对 fd 1/2 的二次 open 未动;<> in pipelines 未动。
  • plan 拒绝形状(legacy 分支)仍按路径 open。
  • set_fd_readwrite_file_from_file 的删除系定序裁决的修正:原裁决谓之“改接”,核查后无采用点存在,删之并记 REPORT §11。

验证状态

UNVERIFIED-BY-CAPTAIN。本轮无构建路线:VM→服务器出口代理中断(198.19.0.1:3128 banner 超时),服务器 Linux 腿与 X299 链同时切断;Simular box 休眠且钱包空;本地无 cargo/rustc/rustfmt,写墙 EDQUOT 间歇关闭。13 格钉从未跑过(fail-first 与修后绿均未证实);lib 双边、RUSTFLAGS="-D warnings" check、fmt/hygiene 均欠。路由恢复后补跑(见 REPORT);在那之前不许称绿。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【P1 车道复核】PR #3835 — 判词:CONFLICT(与当前 master 在 src/executor/shell_options.rs 语义冲突,未合并)

  • head:0c5f166ebd933d3132629db64cfefcb47f9cda2a
  • base merge 尝试:git merge origin/master(master b2e488e54)→ CONFLICT (content): src/executor/shell_options.rs,已 abort,未产生合并提交
  • CI/构建:按流程冲突即停,未构建(PR 自述 13 格钉从未跑过,UNVERIFIED-BY-CAPTAIN)

冲突点(两处,同一函数族)

probe_output_redirect_file / probe_output_redirect_append_file 的尾段:

  • 本 PR 侧:把 probe 的返回类型改为 io::Result<Option<File>>,并新增 special-class 分支——classify_special_path(target) != Filesystem 时 create_redirect_output(...).map(|_| None)(保留 open 只为错误面,不保留 File),普通文件 map(Some)。
  • master 侧(已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功) #3286,6e17fb661 "open output/append FIFO redirects via cwd anchor in bind phase"):在 FIFO 检查之后新增了 output_fifo_validation_via_anchor(executor, None, target),其返回类型是 io::Result<()>;注释写明「deleted cwd 时 joined-path FIFO 检查必然漏判,anchor 的 faccessat 才是 probe 的裁决」。

两者不是相邻行夹具冲突:master 的 verdict 是 Result<()>,本 PR 的函数已改为 Result<Option<File>>,return verdict; 无法机械改写;而且两者都是「probe 阶段该不该真的 open / 用哪个拼写判断 FIFO」的语义裁决(redir.c:237/790/949 单次 open 的前提是 FIFO 判定正确,否则 probe 的 open 会破坏 rendezvous,正是 #1820 的族)。

变绿需要什么

  1. 以合并后的类型为准重写两个 probe 的尾段:先跑 output_fifo_validation_via_anchor(保留 已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功) #3286 的 deleted-cwd 裁决),再落 special-class/plain-file 的 Option<File> 语义;FIFO 裁决为「非 FIFO」时才允许保留 File,保持「每个目标只 open 一次」的不变量。
  2. 补 deleted-cwd × FIFO × umask 0200 的组合矩阵([bug] fifo 双侧基本形状挂死:背景写者 + 前台 read 两形均 timeout(GNU 两形 rc=0) #1820/已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功) #3286/[bug] output redirects fail spuriously when umask strips owner-write from the created file ("f: Permission denied", rc 1, data lost) #3828 三类不能互相回归),并给出 WSL GNU bash 5.3.20 的脚本文件对照。
  3. 本 PR 自述的余项(env 腿、spawn_async_direct、pipeline stage、<>、plan 拒绝形状仍按路径二次 open)与本冲突无关,但一并在 REPORT 里明确「未覆盖」;13 格钉必须先跑出 fail-first(base 红)与修后绿,才能 ready。

未关闭 PR / 未关闭 #3828(保持 OPEN)。

@caomengxuan666

caomengxuan666 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】 PR #3835 第2轮 — 建议:FAIL(merge 已机械解开并推送,但 PR 自身 13 钉在 head 上仍红 5 格)
head: 22ac944e8a5ac4210dac641560ecae092e5d8961(原 0c5f166e + merge 22ac944e8)mergeable: MERGEABLE(冲突已消除)
base(merge-base): 23c0afc64(merge 时 master 尖)关联 issue: #3828(Refs;open)

机制核查:

腿(逐项):

  • 钉自跑(WSL Linux,#![cfg(unix)],setpriv→nobody,脚本文件 tests/issue3828_umask_redirect_permission.rs):
    • master 23c0afc64(钉文件放入):0 passed / 13 failed —— 全红,fail-first 基线成立
    • PR head 0c5f166e(未 merge):8 passed / 5 failed
    • merged 22ac944e8:8 passed / 5 failed —— 与 PR head 完全同集,merge 零回归
    • 红名 = {append_umask_777_data_lands, external_command_redirect_umask_777, group_stderr_redirect_umask_777, preexisting_unwritable_file_still_fails, readwrite_create_only_umask_777}
  • 冲突相邻回归(merged 树,WSL):issue3286_deleted_cwd_fifo 11/0、issue3372_append_funnel 6/0、issue2880_fifo_pairing 5/0、issue1820 3/0、issue1845 3/0、issue1861 3/0、issue1862 6/0、issue1014_umask_inherit 1/0;Windows:issue1472 1/0、issue1486 1/0 —— 已删 cwd 下相对输出重定向至已存在 FIFO 即时 ENOENT(GNU 阻塞 rendezvous 后成功) #3286 anchor 特性完整保留
  • lib 双边(Windows merged 树):1374 pass / 1 fail {api::consumer_tests::issue2084_session_end_restores_host_process_state} —— 与 fix(#3823): funsub ${...} bodies treat # comments and heredocs as opaque spans #3836 两侧同名单的环境性失败,非本 PR 账;master 侧 lib 未单独跑(merged 树已含 master 全部提交,该失败在基线同样出现)
  • -D warnings:cargo check --all-targets 0 警告;marker-lint OK;utf8 clean;rustfmt:8 个 src 文件全 OK,tests/issue3828_umask_redirect_permission.rs 有 minor fmt diff(折行风格,未提交修正,供参考)
  • CI(新 head run 44069092199/44069092316):红 3 项 —— Regression pin stem census、GNU regression goldens and canaries(均已知基线);niubash builds against this tree 挂在 cmp api-ledger.md(byte 62406:rubash 树 ledger 与 niubash master ledger 漂移,跨仓 infra,非本 PR 账)
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1),脚本文件 target/issue-suites/results/e1-3835/drv-umask.sh,setpriv→nobody:

F 点:

  • F1: external_command_redirect_umask_777(钉文件:312)head 红——external spawn preflight→spawn 接线(commit 4 47994a87)未交付,GNU 应 rc=0 数据落盘。
  • F2: group_stderr_redirect_umask_777(:297)head 红——group/compound scope 输出重定向仍二次 open。
  • F3: append_umask_777_data_lands(:248)head 红——append 臂仍二次 open。
  • F4: readwrite_create_only_umask_777(:327)head 红——<> 路径。
  • F5: preexisting_unwritable_file_still_fails(:344)钉期望 out.rc==1 在 GNU 语义下不可达(GNU 脚本末命令 echo rc=$? 恒 rc=0,仅 $?=1)——钉断言写错;另 rubash 重定向失败后 $?=0 vs GNU 1 为相邻残差,请队长定归属。
  • 注:issue1868_empty_output_builtin_still_pairs_fifo_open(FIFO 配对挂死)在 master 23c0afc64 与 PR head 同红——master 基线红,非本 PR 账,但属近期 master 回归,建议单独立案。

续作记录:

  • 22ac944e8 Merge remote-tracking branch 'origin/master' —— shell_options.rs 两 hunk 按上述唯一解法解决 + rustfmt 7 文件;新 head: 22ac944e8a5ac4210dac641560ecae092e5d8961(已 push,gh 复核 MERGEABLE)

未跑/VOID 的腿:

  • 钉文件 13 格中 create_only_umask_0266 等其余 8 格已绿,无需补
  • 服务器 CI 全量 stem census 明细未逐条归因(基线 ~36 stem 红为已知项)

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】f1 冲突阻塞复核(第3轮)— 建议:FAIL(维持前轮判词;冲突已由前轮解开,本轮核实对现尖仍干净)

head: 22ac944e8a5ac4210dac641560ecae092e5d8961(自第2轮 merge origin/master@23c0afc64 后未推进)
mergeable: MERGEABLE / UNSTABLE(gh 实时,2026-11-17 19:5x CST)
关联 issue: #3828(Refs;open)

本轮 f1 分工仅为冲突面核实:

  • git merge-tree --write-tree origin/master(a41909d3) 22ac944e8 → rc=0,tree 2b88094c,无冲突文件 —— master 自 23c0afc64 前进至 a41909d3 后,本 PR 仍可干净合入,冲突阻塞已解除。
  • head 自第2轮未变:第2轮已跑腿继续有效(WSL 钉 8p/5f、lib 差集、-D warnings 0、CI 逐名归因),本轮不重复计为新证。

F 点(沿用第2轮,head 未变故不重跑):

  • F1-F5:append_umask_777_data_lands / external_command_redirect_umask_777 / group_stderr_redirect_umask_777 / readwrite_create_only_umask_777 / preexisting_unwritable_file_still_fails 五格钉在 head 仍红——PR 未交付其自述覆盖范围;F5 另含钉断言在 GNU 语义下不可达(脚本末命令恒 rc=0),归属待队长裁定。
  • 另:issue1868_empty_output_builtin_still_pairs_fifo_open 在 master 基线同红(非本 PR 账,前轮已建议单独立案)。

续作记录:无(本轮未改代码、未 push)。
未跑/VOID 的腿:无新增;全部腿沿用第2轮(head oid 相同)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

[i2 续作] head: af9dea0 (was 22ac944)

续作 commit af9dea032 — 接续本 PR 的「每 redirect entry open 一次」机制,补外部命令面最后一处双开:

  • external_file_builtins.rs: 模拟外部命令的预检在知道 emulation arm 是否接管前就跑了 apply_redirect_setup_side_effects;literal 可执行拼写(/bin/pwd、/bin/printf 等)会 decline 到真实 exec 路径,预检的 probe open 先按 umask 剥掉写位创建目标,execute_external_inner 自己的 preflight open 随后 EACCES。现按 emulated && !literal_file_declines 门控,该 walk 只在确实会被模拟的命令上执行。GNU 依据:redirection.c:237 do_redirections → redir_open(redir.c:949)每 entry 只 open 一次。

钉自跑(WSL Linux,setpriv --reuid=nobody DAC 强制,cargo test --test issue3828_umask_redirect_permission):9 passed / 4 failed(续作前 8/5)。external_command_redirect_umask_777 转绿。

剩余 4 红的归因(WSL GNU Bash 5.3.20(1)-release 逐字节对照):

  • append_umask_777_data_lands、preexisting_unwritable_file_still_fails:钉的期望与 GNU 5.3.20 实测矛盾。GNU 下 umask 777; echo a >> f7; echo b >> f7 第二次 >> 是对 mode-000 已存在文件的新 open → Permission denied rc=1、内容仅 a\n;rubash 现与 GNU 逐字节一致(stderr/stdout/rc/文件 mode 与内容全同)。preexisting 用例 driver 末尾是 echo rc=$?,进程 rc 恒为 0,assert_eq!(out.rc, 1) 在任何正确 shell 上都不可能成立(GNU 同样 proc_rc=0、stdout rc=1)。建议钉面修正,未按错期望改产品代码。
  • group_stderr_redirect_umask_777({ ... } 2> f10):真实残留双开——compound 准备期 probe open(probe_output_redirect_file ← redirect_setup_open_error ← pregate_redirect_open_check)创建 mode-000 文件后丢弃,scoped bind 再按路径 open → EACCES。需把 compound 输出准备的已开 fd 接入 preopened 通道。
  • readwrite_create_only_umask_777(: <> f12):真实残留双开——reject 门 probe(redirection.rs ReadWrite 分支 FileFd::open_readwrite_pair(path).map(|_| ()),或 anchored_redirect_probe)open 后丢弃,fd0 bind(open_readwrite_pair/set_fd_readwrite_file 一带)再 open → EACCES。需给 input/readwrite 侧建同样的「open 一次、bind 领养」通道。

未跑/VOID:lib 双边、-D warnings、fail-first、CI 核查——本轮只到钉自跑 + GNU 对照,建议判词 PENDING(缺腿),两处真实残留需要下一轮续作。

@caomengxuan666

Copy link
Copy Markdown
Member Author

[h2 续作] PR #3835 第4轮 — 建议:PENDING(缺腿:lib双边 VOID + push 被远端 head 推进阻断)
head: 本地 480e46683(22ac944e8 + 1 commit,10 文件 +317/-69);远端已推进至 af9dea032(i2 续作,外部命令面互补修复)— 按「head 变了停手」规程未 push
base(merge-base): 67f80a2aa 关联 issue: #3828(open)

机制核查:

  • GNU 每 redirect entry 只 open 一次:redir.c:237 do_redirections → redir.c:790 do_redirection_internal → redir.c:949 redir_open。本 commit 新增 Executor::pending_preopened_redirects(按 cmd.redirects 位置键控 + target/path 校验 + 消费一次),把 validate/prepare walk 的成功 File 传给 bind walk 采用,不再按路径重开。覆盖:外部命令预检→spawn、brace 组 prepare→compound bind、<> reject-gate O_RDWR、external file builtins retained 变体;FIFO/network/合成路径仍走唯一 bind-time open。
  • diff 无可疑/无关改动(工作区 src/parser/* 脏改为既有 [parser] reserved words after pending-inversion ! run as command words instead of syntax errors (siblings of #3648) #3833 残留,未入 commit)。

腿:

  • 钉自跑:issue3828_umask_redirect_permission 13/13 ok(head 480e46683,WSL)
  • fail-first:base 67f80a2aa + 钉原样 → 0/13 全红(红名=全部 13 格;PR 声称 5 格 ⊂ 实测,base 上 umask 0644/0600/0222/0266 同样 owner 不可写,面更宽)
  • lib 双边:VOID — WSL /dev/sdd 100%(0 可用),lib test 需数百 MB 新产物无法写入
  • -D warnings:cargo check --locked --bin rubash → 0 警告
  • 卫生:改动文件 rustfmt --check 干净
  • CI:未跑(head 未推送)
  • GNU 对照:/usr/local/bin/bash = GNU Bash 5.3.20(1)-release;scratch-h2/gnu-cmp-3828.sh → 9/9 逐字节一致(rc+stdout+归一化 stderr+文件 mode/sha)

F 点(前轮 5 格红)逐条:

  • F1 append_umask_777_data_lands:钉期望错 — GNU 下第二个 >> 重开 mode-000 文件同样 EACCES(rc=1、首行保留、脚本 rc=0,oracle 实测);断言已按 GNU 修正
  • F2 external_command_redirect_umask_777:已修(预检 retained → spawn 采用)
  • F3 group_stderr_redirect_umask_777:已修(prepare retained → bind 采用)
  • F4 readwrite_create_only_umask_777:已修(reject-gate O_RDWR 驻留)
  • F5 preexisting_unwritable_file_still_fails:钉期望错 — GNU echo hi > f13; echo rc=$? 末条 echo 使脚本状态 0、打印 rc=1;断言已按 GNU 修正

续作记录:

阻断/待决:

  1. 远端 head 推进:af9dea032 与本 commit 在 external_file_builtins.rs 同一调用点冲突(git merge-tree 实测仅此 1 处)。语义合解 = 保留 i2 的 literal_file_declines 门 + 改用 _retained 调用。请队长裁定由谁 rebase 后推送。
  2. lib 双边 VOID:磁盘。另 /root 下 l01/l02/l05/l07/l09/l11-target 合计 ~90GB 为 11-14 日 stale 产物(非本 lane,未动)——建议清理以解全 WSL 构建。
  3. 相邻残差(未验证,未扩范围):真正被 emulation arm 接管的命令在 umask 屏蔽目标下,arm 的 fd mirror 按路径重开是否仍双开——磁盘阻断构建未能验证。

未跑/VOID 的腿:lib 双边(head/base);合并态钉复跑;marker-literals/utf8-boundary 脚本。

caomengxuan666 and others added 7 commits November 18, 2026 00:01
…e open (Refs #3828)

GNU opens each output redirect target exactly once per redirect
entry (redir.c do_redirections / do_redirection_internal /
redir_open). The ordered walk's create/append open IS the entry's
open: keep the File as a SharedFile instead of dropping it and
re-opening by path at flush time — a target created with a mode
lacking owner-write (umask masking 0200) fails the second open
with EACCES although the kernel-level single open succeeds.

Adds the File-returning probe twins
(probe_output_redirect_file / probe_output_redirect_append_file);
the ()-returning probes delegate to them, unchanged for callers.
FIFO / net / special-class targets keep no File here.

Inherited uncommitted work of the prior continuation lane,
verified hunk-by-hunk against the issue and GNU semantics by
the captain-direct continuation; the probe-then-bind wirings
(exec / group / null-command / external spawn) follow in the
next commit. UNVERIFIED-BY-CAPTAIN.
…ets (Refs #3828)

GNU opens each output redirect target once per entry (redir.c:237
do_redirections -> do_redirection_internal, redir.c:790 -> redir_open,
redir.c:949); under a umask masking 0200 the created file lacks
owner-write and rubash's second open by path fails EACCES. Pins cover
create/write/append, exec 3>/2>, group 2>, external /bin/echo, <> and
the pre-existing-444 control.
…s own open (Refs #3828)

GNU opens each output redirect target once per entry (redir.c:237
do_redirections -> do_redirection_internal, redir.c:790 -> redir_open,
redir.c:949). The persistent-exec walk and the compound scope walk
probed the target (creating it) and then bound it with a second open
by path; a target created with a mode lacking owner-write (umask
masking 0200) fails that second open EACCES. Adopt the probe's File
via probe_output_redirect_file + set_fd_output_file_from_file, so the
probe's open IS the entry's one open. FIFO / net / special targets
probe to None and keep the plain bind, whose open stays their single
pairing open (rubash#2880); append arms already bind in one open.
…rough the probe's own open (Refs #3828)

GNU opens each redirect target exactly once per entry (redir.c
do_redirections :237 / do_redirection_internal :790 / redir_open
:949); a target created with a mode lacking owner-write (umask
masking 0200) fails a second open with EACCES although the single
open succeeds. This completes the probe-then-bind sequencing:

- external spawn: execute_external_inner runs the preflight as
  command_output_redirect_fails_with_preopened and hands its
  preopened map to the plan (fd 1/2 adopt the gate's description
  via adopt_preopened_combined_target) and to the spawn delivery
  (fd >= 3 adopt via the existing collect_external_fd_delivery
  preopened channel, rubash#3311). The env leg and the async
  spawn paths run no preflight and keep opening by path (residual).
- no-output builtins: redirect_setup_open_error records the list
  positions it really opened (plain filesystem targets only); the
  mirror skips its own re-open at recorded positions. Input
  entries are never recorded (the mirror's positional probe may
  resolve a different in-list binding); `>&WORD` is a first open
  (DuplicateOutput is never probed).
- dedup: the duplicate set_fd_output_file_from_file definition
  and the unadopted set_fd_readwrite_file_from_file are removed
  (exec/compound `<>` are single-open already; the mirror uses
  the skip-set, so no adoption site exists); the bool-only
  command_output_redirect_fails wrapper and the now-unused
  probe_output_redirect_append wrapper are removed.

Pins (tests/issue3828_umask_redirect_permission.rs, 13 cells)
are UNRUN: no build route (VM->server egress proxy down, box
hibernated, no local cargo). Legs owed after the route recovers:
pin stem + lib bilateral + RUSTFLAGS="-D warnings" check + fmt.
…lesystem check (Refs #3828)

CI run 44038661354 failed the lib build with E0308 at
src/executor/redirection.rs:3734:65: classify_special_path takes &str
(special_paths.rs:119) but the walk's target is a String here
(redirect_output_path_target returns String, shell_options.rs:2733).
Borrow it; no behavior change.
…h to real exec (Refs #3828)

The emulated-external preflight ran apply_redirect_setup_side_effects
before knowing whether an emulation arm would answer. For literal
executable spellings (/bin/pwd, /bin/printf, ...) the arms decline to
the real exec path, so the walk's probe open created the target under
the umask-stripped mode and execute_external_inner's own preflight
open then failed EACCES — GNU's single do_redirections open
(redirection.c:237 -> redir_open redir.c:949) succeeds once. Gate the
walk on emulated && !literal_file_declines so only commands an arm
will actually emulate pay the side-effect walk.
…lk (Refs #3828)

GNU do_redirections opens every redirect entry exactly once
(redir.c do_redirection_internal -> redir_open). rubash splits that
open across an earlier validate/prepare walk and a later bind walk;
the first walk dropped its File, so the bind re-opened the path and
failed EACCES on a file created without owner-write (umask masking
0200). Retain the first walk's FileFd in pending_preopened_redirects
keyed by cmd.redirects position; consumers adopt on exact target
match, so stale entries can never bind the wrong file.

- external commands: apply_redirect_setup_side_effects_retained feeds
  the spawn gate's preopened map (was: probe opened, gate re-opened)
- brace groups: prepare_brace_group out/err arms retain via
  create_redirect_output_prepared_open_for; the compound bind adopts
- `<>`: the reject gate's open_readwrite_pair parks its FileFd; the
  setup walk's probe skips the already-opened position
- pins: append/control expectations corrected to verified GNU 5.3.20
  behavior (second `>>` and the script rc are GNU's own answers)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 force-pushed the fix/3828-umask-redirect-permission branch from af9dea0 to f4ba7d9 Compare November 17, 2026 16:13
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-REWORK】h2 续作完成 — 建议:PASS
head: f4ba7d9c8(rebase onto origin/master 41279ae9;含 f1 全部 6 commit + i2 af9dea032 + h2 pending_preopened_redirects 机制)

产品面 5 格红的修复(承接上轮 PENDING):

  • 机制:GNU redir.c:237 do_redirections → :790 do_redirection_internal → :949 redir_open 每 entry open 一次。h2 commit 把 validate/prepare walk 的成功 File 经 pending_preopened_redirects(按 cmd.redirects 位置键控 + target/path 校验 + 消费一次)传给 bind walk 采用,覆盖外部命令预检→spawn、brace 组 prepare→compound bind、<> reject-gate O_RDWR、external file builtins retained 变体。
  • 与 i2 af9dea032 的关系:i2 修「literal /bin/pwd,/bin/printf 落真实 exec 时跳过预检 walk」;h2 修「walk 开了就把 File 带给 bind」。两者互补、无语义冲突——rebase 冲突仅 external_file_builtins.rs 一处调用点,合解 = 保留 i2 的 literal_file_declines 门 + 改用 _retained 调用。
  • 钉修正 2 格(期望本身错,已按 GNU 5.3.20 oracle 实测修正):append_umask_777(第二个 >> 重开 mode-000 同样 EACCES,rc=1/脚本 rc=0)、preexisting_unwritable(末条 echo rc=$? 使脚本状态 0)。

腿(全在 rebase 后 head f4ba7d9c8 实跑):

  • 钉自跑:issue3828_umask_redirect_permission 13/13 ok
  • fail-first:base 41279ae9 + 钉原样 → 1/13,红名 = {append_umask_777_data_lands, create_only_umask_0266_succeeds, create_only_umask_777_succeeds, exec_persistent_redirect_umask_777, exec_stderr_redirect_umask_777, external_command_redirect_umask_777, group_stderr_redirect_umask_777, readwrite_create_only_umask_777, write_umask_0222/0600/0644/777_data_lands}(PR 声称 5 格 ⊂ 实测;preexisting_unwritable_file_still_fails 在 base 本就绿——首个 open 即 EACCES,无第二次 open 问题)
  • lib 双边:head 1274 passed / 0 failed / 4 ignored vs base 1274 / 0 / 4,差集 = ∅
  • -D warnings:cargo check --locked --bin rubash → 0 警告
  • GNU 对照:/usr/local/bin/bash = GNU Bash 5.3.20(1)-release;scratch-h2/gnu-cmp-3828.sh → 9/9 逐字节一致(rc+stdout+归一化 stderr+文件 mode/sha)
  • 卫生:改动文件 rustfmt --check 干净;continuation.rs 不在 diff(已核)
  • CI:push 后由 CI 跑(mergeable: MERGEABLE)

rebase 冲突处理:shell_options.rs 2 处(master #3286 anchor 校验并入 _file/_append_file 双胞胎,verdict.map(|_| None) 适配)、command_input_scope.rs 4 处(master #3733/#3806/#3815 改的是输入面/邻近区,本 commit 的输出 bind 区无语义重叠,全取 h2 侧)、external_file_builtins.rs 1 处(i2 门 + _retained)。无产品语义冲突。

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