Repository navigation
WIP: posix batch — pipeline special preclusion (#2081) + special redirect failure exits (#2082) - #2112
Merged
Conversation
GNU execute_cmd.c:4657-4663 (execute_simple_command): in posix mode special builtins are found before functions — find_function is never consulted for one. Every pipeline element reaches that same classification through execute_pipeline (execute_cmd.c:2620), but rubash's stage driver fall-through for unclaimed names entered execute_function_pipeline_stage with no preclusion, so a function shadowed all 16 special builtins on the pipeline face while the top-level face (execute_function_command_invocation) already declined. State the preclusion at the function route itself so every stage path inherits it: the stage declines when the expanded stage name is a posix special builtin and posix mode is on. Probes (script files vs GNU bash 5.3.20): `source /dev/null | cat` and `. /dev/null | cat` with same-named functions defined printed the function markers before, print nothing now; `eval 'echo IN' | cat` prints IN now; the default-mode control still runs the functions. Regression pins in tests/issue2081_posix_pipeline_special_regressions.rs (6 tests; 4 fail / 2 pass on the base tree, 6/6 with the fix). Fixes #2081
…tive posix shell GNU: execute_builtin_or_function's do_redirections failure returns EX_REDIRFAIL (execute_cmd.c:5613), and execute_simple_command's conversion (execute_cmd.c:4865-4875) exits a posixly_correct, non-interactive shell at EXECUTION_FAILURE when the builtin is special — the jump fires inside execute_simple_command, so tested contexts (||, if, !) do not contain it and no ERR trap runs, while non-special builtins, disk commands and functions convert through builtin_status (execute_cmd.c:4896-4901) to a plain status 1. Rubash split that one verdict across two channels and converted neither: the reject gate (reject_invalid_redirects — dup/input-open/ambiguous class) abandoned the command with status 1 and kept going, and the apply layer's IoError was rendered by execute_command's arm and likewise continued (only set -e converted, with an ERR trap GNU does not fire here). Convert at both channels behind one gate (posix mode, non-interactive, first word in the registry's 16-name special set, not under a `command` re-dispatch, not enable-disabled to the filesystem): execute_materialized_command returns ExitCode(1) for a RedirectRejection::Command under the gate, and execute_command's IoError arm converts after rendering the diagnostic. Subshell and command-substitution executors contain the ExitCode as the child's own status, matching GNU's containment; a pipeline element dies as the element with status 1. Probes (script files vs GNU bash 5.3.20): the issue's four shapes (`.`, `source`, `:`, `eval` with <&9) exit 1 with no following line; also verified cell-by-cell: missing-file input and output opens, export, || / if / ! contexts, `command` prefix, function call and function body, subshell, command substitution, pipeline stage, EXIT-trap-runs / ERR-trap-silent, set -e stacking, and the default-mode and non-special controls. Regression pins in tests/issue2082_posix_special_redirect_failure_regressions.rs (15 tests; the exit shapes fail on the base tree, 15/15 with the fix). Fixes #2082
…L fix Per the re-record protocol in tests/regression.rs: the byte shift is caused by the rubash#2082 engine change in this PR (special builtin redirection failure now exits a posixly_correct non-interactive shell, GNU execute_cmd.c:4865-4875). The shifted face is upstream errors3.sub, whose own header states the semantics — "redirection errors with special builtins should exit the shell when in Posix mode... being on the LHS of || or && should not make a difference": its second `exec 9<no_such_file || echo TEST` (after `set -o posix`) no longer prints TEST because the shell exits, exactly as GNU bash 5.3.20 does (verified directly: one TEST, exit 1). The stale bytes pinned the pre-fix behavior #2082 was filed against. Bytes are the runner-true re-record uploaded by this PR's CI run (artifact regression-snapshots, run 40878809342): only errors.snap changes, by this one line; the other twelve slices are byte-identical. Refs #2082
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
POSIX 模式批两单(逐单 commit、CI 为门、未自合):
#2081 — 管线 stage 面不认 POSIX special 先行(commit a117434)
GNU execute_cmd.c:4657-4663(execute_simple_command):posix 模式下 special builtin 先于函数被找到,find_function 根本不被咨询;每个管线 element 经 execute_pipeline(execute_cmd.c:2620)走同一分类。rubash 的 stage 驱动对未认领名的兜底路径无条件先进
execute_function_pipeline_stage,绕过了简单命令面已有的谓词点,16 个 special 名在管线面全被同名函数遮蔽。修法:把排除条件写在函数路由自身(展开后的 stage 名是 posix special 且 posix 开 → decline),所有 stage 路径(顺序兜底、shell-writer 生产者)一并继承。钉 6 条:基线 4 红/2 绿(两绿为本就正确的对照形),修复后 6/6。#2082 — special builtin 重定向失败在 posix 非交互下不退 shell(commit 0c9e6ec)
GNU:do_redirections 失败返回 EX_REDIRFAIL(execute_cmd.c:5613),execute_simple_command 的转换(:4865-4875)对 special×posix×非交互直接 jump 退 shell(rc=1)——跳转发生在 execute_simple_command 内部,故
||/条件/取反都拦不住、ERR trap 不跑、EXIT trap 照跑;非 special/外部/函数走 builtin_status 转 1 继续。rubash 把这一裁定拆成两条未转换的通道:拒绝门(dup/输入打开/歧义类 → RedirectRejection::Command)与施加层(输出打开等 → IoError 臂),都只报错续跑。修法:同一谓词门(posix × 非交互 × 16 名 special 全类 × 非command重派发 × 非 enable 禁用)下两处转换——门通道在 execute_materialized_command 的 outcome 前返回 ExitCode(1),施加层通道在 execute_command 的 IoError 臂渲染诊断后转换;子shell/comsub/管线 stage 按 GNU 语义内含。钉 15 条:基线退出形全红,修复后 15/15;另与 GNU 5.3.20 脚本对照矩阵逐格一致(四名 + export + 输入/输出打开失败 + 全部上下文格 + 对照格)。本地门:两钉文件全过、
cargo check --all-targets带-D warnings干净、改动文件 rustfmt + LF。全量裁定走本 PR 的 CI。Fixes #2081
Fixes #2082
快照重录(commit 3a6550a):首轮 CI 的 Windows goldens 仅 errors 片红一格——上游 errors3.sub 第二行
exec 9<no_such_file || echo TEST(set -o posix 之后)不再打印 TEST,因为 shell 按 #2082 语义退出了。已对 GNU 5.3.20 oracle 直跑裁定:GNU 同样只打印一行 TEST 并以 1 退出(该 .sub 文件头注释自述正是此语义),旧快照钉的是修复前错误行为。按 tests/regression.rs 的重录协议,采用本 PR CI 上传的 runner-true 工件字节(run 40878809342 的 regression-snapshots)落盘:仅 errors.snap 删一行,其余十二片逐字未动。