Repository navigation
fix(executor): undo partial binds on mid-list redirect failure (Refs #3733) - #3853
Conversation
…3733) GNU's do_redirections registers an undo save per entry (add_undo_redirect, redir.c:1326 — kernel fcntl F_DUPFD saves) and undo_partial_redirects (execute_cmd.c:855) replays them when a later entry fails, so a failed list leaves the fd table exactly as found. Rubash's compound/function scopes already accumulate SavedNumberedFd/SavedOutputFd snapshots for scope-end restore, but the numbered-input wrapper dropped them on the _in error path: `{ :; } 8<f9 9<f8 7</non/nope` left fd 8 reading f9 and fd 9 reading f8. Restore the accumulated snapshots before propagating, mirroring the output wrapper's existing unwind. The same-exe script face's segmented walk (bind_script_numbered_inputs_and_fd_vars) had the identical hole: its Err arm now restores the numbered input/output snapshots and the {var} close records the walk performed, in the scope's outputs->inputs->dynamic unwind order. Pin: tests/issue3733_redirect_mid_list_undo.rs (49 cells, cfg(unix); 28 red on the unfixed base, all green with the fix; WSL cargo test native, siblings issue3706-3732 + redirect stems green). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】h1 续作完成 — 建议:PASS(待队长终审) 机制核查:
腿:
相邻残差(未扩 scope):输入/输出两遍绑定 vs GNU 单次 walk 的副作用顺序差(文件创建时机),fd 状态两侧正确,建议另立 issue。 |
|
【WIN-AGENT-AUDIT】i1 审计 — 建议:PASS(#3853) PR #3853 第1轮 — 建议:PASS 机制核查:
腿(逐项数字):
分歧/残差(如实上报,不阻塞本 issue 的 fd-table 语义范围):
F 点:无 未跑/VOID 的腿:无(macOS CI 腿以 WSL Linux 原生测试替代,已在 CI 条注明) 续作记录:本轮未改代码(审计-only)。 独立复核备注:h1 lane 已有 PASS 建议评论,本报告为 i1 独立审计结论,两者一致。 Generated with Devin |
|
【WIN-AGENT-AUDIT】i1 批次汇总 — i1 波 3 条 g1 修复 PR 审计完毕
阻塞项:无。CI 侧 census+goldens 为已知基线红;#3853 的 macOS job 为 infra cancelled(零日志不可归因),钉为 cfg(unix),Linux 原生已覆盖。 Generated with Devin |
Summary
Fixes #3733
add_undo_redirect(redir.c:1326, kernelfcntl (fd, F_DUPFD, SHELL_FD_BASE)at redir.c:965/1082/1144) and replays them viaundo_partial_redirects(execute_cmd.c:855) whendo_redirectionsreturns an error.SavedNumberedFd/SavedOutputFdsnapshots for scope-end restore, butopen_compound_numbered_input_redirects(command_input_scope.rs) dropped the accumulatedsavedvector on the_inerror path — so{ :; } 8<f9 9<f8 7</non/nopeleft fd 8 reading f9 and fd 9 reading f8. The output wrapper already unwound on error; the input wrapper now mirrors it.bind_script_numbered_inputs_and_fd_vars(trap_exec.rs): itsErrarm now restores the numbered input/output snapshots and the{var}close records the walk performed, in the scope's outputs → inputs → dynamic unwind order. (That face is only reachable from library hosts —owns_process_image == false— so no CLI reproducer; the arm is mechanism-aligned with the in-shell fix.)tests/issue3733_redirect_mid_list_undo.rs— 49 cells,#![cfg(unix)], covering every compound face (while/until/for/if/case/select/brace/inverted/time/nested/function-def), fd 0/3/8/9/12, heredoc binds,{var}close/dup composition, move/close entries, output/append/<>binds, and controls.GNU basis
execute_cmd.c:854-856— compound/control commands rundo_redirections (..., RX_ACTIVE|RX_UNDOABLE)and callundo_partial_redirects()on failure.redir.c:1326 add_undo_redirect— undo save = kernel dup of the displaced descriptor; undo list is LIFO.execute_cmd.c:5608area — builtin/function redirections get the same undoable treatment./usr/local/bin/bash) from script files:{ :; } 8<f9.txt 9<f8.txt 7</non/nopeleaves fd8=f8a/fd9=f9a; rubash pre-fix left them swapped.Adjacent residual (not fixed here — separate face)
do_redirections(redir.c:237) is one ordered walk. Observable only as open side-effect ordering:{ :; } 8>newfile 7</non/nope— GNU createsnewfile(the>open ran before the failure); rubash does not (input pass fails first). FD-table state after the failure is correct in both. Fixing this needs interleaved input/output binding — architectural, out of 1.5.1 scope.{var}ambient binds/var-values fromapply_dynamic_fd_var_redirectsare undone byundo_child_fd_var_redirects's own records; this change restores only what the segmented walk itself accumulated.Validation
3d8c9ff8f), all 49 green with the fix — WSL Linux nativecargo test(rustc 1.98.1,/root/.cargo),CARGO_TARGET_DIR=target-wsl.RUSTFLAGS="-D warnings" cargo check: clean.rustfmt --checkon touched files: clean.check-marker-literals.py: OK.check-utf8-boundary-hygiene.sh: clean.target/debug/rubash.exe): c1/c2/c3 compound faces + h1-h4 output/fd0/dupclosed shapes — fd-state and file-creation side effects byte-identical post-fix.Test plan
cargo test --test issue3733_redirect_mid_list_undo(WSL native): 49/49Generated with Devin