Repository navigation
fix(executor): #846 — '!' must not invert a compound's own redirect failure - #897
arookieofc wants to merge 1 commit into
Conversation
…ailure
GNU execute_cmd.c:854-883 splits redirection timing by command kind:
a shell control structure ({}/()/if/while/for/case/[[ ]]/(( ))/select)
runs do_redirections BEFORE the body, and a failure there is
EXECUTION_FAILURE — invert only gates errexit/the ERR trap (:868),
never the return status. A simple command's redirect failure is part
of the command's result and '!' flips it.
Rubash's execute_inverted_ast_command inverted exit_code blindly, so
'! { :; } > /bad' reported 0 against GNU's 1.
This adds a compound_redirect_failure flag on Executor, set at every
compound pre-execution redirect failure point (brace splice, subshell
stdio splice, if/loop/case/select body redirects, [[ ]] / (( )), and
read+cleared by execute_inverted_ast_command which skips the flip when
set.
GNU anchors: execute_cmd.c:854 do_redirections, :883 return
EXECUTION_FAILURE, :868 invert gates error trap / errexit only.
Verified against WSL GNU bash 5.3.15(1) on the full matrix in the
issue comment plus ! inner-failure and set -e faces.
|
欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。 |
独立评审裁决(#897 vs #902 同票双 PR)本 PR 与 #902 同为 closes #846。按双分支自建 worktree 实测裁决:建议不合入本 PR,合入 #902 并将本 PR 以 superseded 关闭。评审方法:master / #897 / #902 三树自建构建(6e600e5a / bbf06a0,debug),oracle 为 WSL GNU bash 5.3.0(1)(/usr/local/bin/bash),60 形矩阵(52 计划形 + 8 边界探针形)逐形态比对 rc+stdout+stderr(程序名前缀与 time 计时行归一化)。交叉裁决评论见 #902。 实测分歧(仅列有差异的形态,
|
| 形 | GNU 5.3.0 | master | #897 | #902 |
|---|---|---|---|---|
! coproc true > BAD |
1 | 0 | 0 ✗ 未覆盖 | 1 ✓ |
{ :; } > BAD; ! false |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
( ! { :; } > BAD ) |
0 | 0 | 1 ✗ 回退(票面明示子壳形原本已一致) | 0 ✓ |
! ( { :; } > BAD ) |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
f() { { :; } > BAD; }; ! f |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
set -e; ( ! { :; } > BAD ); echo cont=$? |
cont=0, rc 0 | 同 GNU | rc 1(errexited)✗ 回退 | 同 GNU ✓ |
eval '{ :; } > BAD'; ! { false; } |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
( { :; } > BAD ); ! { false; } |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
f() { { :; } > BAD; }; f; ! { false; } |
0 | 0 | 1 ✗ 回退 | 0 ✓ |
echo pre; ! true | cat > BAD; echo post |
pre+post | 仅 pre | 仅 pre(未修的预存 stdout 吞没) | pre+post ✓ |
核心矩阵(brace/subshell/if/while/until/for/for (( ))/case/[[ ]]/(( ))/select/! true > BAD 对照、set -e 直面、ERR trap 门、|| 可见面、rc=$? 可见面、! ! 双重否定)两 PR 均与 GNU 一致;本 PR 对 ! time { :; } > BAD(GNU rc 1)也实测正确。
机制判定
本 PR 的 compound_redirect_failure Cell 对孤立复合形机制正确,但标志只有 execute_inverted_ast_command 一个读后清除点,没有边界生命周期:mark 点无条件置位,一旦置位后没有经过 inverted 复合消费(普通 { :; } > BAD、函数体、eval 串、subshell 区域内),标志就跨命令滞留,吞掉下一个 ! 复合 的合法翻转——上表 8 个回退形全部由此产生(其中 5 个是 master 本来正确的形态被回退)。coproc 无 mark 点(GNU :2583 coproc 自面)。自带 3 测试全绿但覆盖盲区正是这些序列/边界形。
#902 的 leave-set + 边界消费模型(pipeline wait-side :763 恒翻转并消费、subshell 区域 :1831 单体 inverted 提升、function/eval/source/comsub 边界清除、每命令回扫清除)与 GNU 的结构逐点对应,60 形中除两处双方共有且预存的分歧(中段 stage 重定向失败中止后续 echo A | cat > BAD | cat,GNU rc 0;time 对失败前管道不打印计时,表层差异)外全部 GNU 逐字节一致。#902 还附带修复了 master 上实测存在的 pipeline stage 重定向失败吞没后续 stdout 的预存缺陷(本 PR 未含)。
两 PR 在 command_prepare.rs / compound_exec.rs / command_dispatch_late.rs / loop_select.rs / select_exec.rs / pipeline_exec.rs / mod.rs / init.rs / command_substitution.rs 文本重叠,#902 合入后本 PR 无法干净合入。
处置建议
- 合入 fix(executor): #846 - ! no longer flips a compound's own redirect failure #902(基于当前 master,单提交,CI 7 项绿,本地 9/9 新测试绿)。
- 本 PR 关闭为 superseded by fix(executor): #846 - ! no longer flips a compound's own redirect failure #902;其 3 测试用例面(errexit 直面等)可择机并入 fix(executor): #846 - ! no longer flips a compound's own redirect failure #902 的
tests/issue846_bang_redirect_regressions.rs作为补充面(非阻塞)。 - 遗留跟踪(两 PR 共有、fix(executor): #846 - ! no longer flips a compound's own redirect failure #902 已如实披露):中段 stage 输出重定向失败中止后续管道阶段,建议单独开票。
Fixes #846
GNU execute_cmd.c:854-883 splits redirection timing by command kind: a shell control structure ({}/()/if/while/for/case/[[ ]]/(( ))/select) runs do_redirections BEFORE the body; failure is EXECUTION_FAILURE which invert only gates for errexit/ERR trap, never the return status. A simple command's redirect failure is part of the command result and '!' flips it.
Rubash's execute_inverted_ast_command inverted exit_code blindly, so '! { :; } > /bad' reported 0 against GNU's 1.
Adds a compound_redirect_failure flag on Executor, set at every compound pre-execution redirect failure point (brace splice, subshell stdio splice, if/loop/case/select body redirects, [[ ]] / (( ))), and read+cleared by execute_inverted_ast_command which skips the flip when set.
Verified byte-exact against WSL GNU bash 5.3.15(1) on the full matrix from the issue body plus ! inner-failure and set -e faces (double_bang, errexit suppression).