Repository navigation
exec: classify bad interpreter on the exec builtin face via shell_execve (Refs #3148) - #3214
Merged
Merged
Conversation
…assification The exec builtin's three spawn-failure reporting points (the process-replacement path and the two simulated paths) each formatted the raw io::Error text with an `exec:` infix and a bare ENOENT ? 127 : 126 status switch, never reusing the executor's existing classification. They now share report_exec_spawn_failure: - classification comes from spawn_error_diagnostic, whose #! sample check is reordered to the GNU arm sequence in shell_execve (execute_cmd.c:6126; the sample classification at :6184 is errno-agnostic, so an EACCES interpreter also yields the bad-interpreter report with the actual errno text at EX_NOEXEC); - the bad-interpreter family reports through a new builtin-layer sys_error_prefix (error.c:275 error_prolog (0): no line segment, no builtin-name infix); the sibling families keep the line segment (error.c:126 file_error); - the report name is rebuilt as full_pathname (builtins/exec.def:172; general.c:931-943 sh_makepath MP_DOCWD|MP_RMDOT) from the typed word or the PATH walk's as-written join, so no `/./` residue survives. Refs #3148
This was referenced Nov 10, 2026
caomengxuan666
marked this pull request as ready for review
November 11, 2026 11:28
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.
Refs #3148
问题
exec内建面执行#!解释器缺失的脚本时不做 shell_execve 分类:报原始 OS 错误文本、带line 1:行段与exec:中缀、退出码 127。GNU 走 shell_execve 的 sys_error 分类:case.sh: /tmp/<fixture>/badinterp: /nonexistent-interp: bad interpreter: No such file or directory,退出码 126,报告名为 exec.def 的 full_pathname 形(cwd 拼合、无/./残留)。根因
src/builtins/exec.rs的三个 spawn 失败报告点(进程替换路径replace_process_image、模拟路径run_external_exec/run_external_exec_with_stdio)都自成一套:替换路径用(errno == ENOENT) ? 127 : 126裸切换 + 原始io::Error文本,模拟路径恒 126 + 原始文本,均未复用执行器已有的spawn_error_diagnostic分类(普通命令面 [B6-R18] Bad-interpreter exec diagnostic carries aline 1:segment GNU omits #2755 已修)。program显示形,session-cwd 锚定保留了 join 的/./,而 GNU 在 builtins/exec.def:172 先以full_pathname(general.c:931,cwd 拼合 + MP_RMDOT)重绑报告名。修法
report_exec_spawn_failure:分类复用执行器spawn_error_diagnostic(经executor/mod.rs以pub(crate)再导出),prolog 按分类家族二选一——bad-interpreter 走新增的 builtin 层sys_error_prefix(error.c:275 error_prolog(0),无行段、无exec:中缀),其余分类保留diagnostic_prefix的行段;报告名按 exec.def:172 以exec_report_name从 typed word / PATH walk 的 as-written join 重建 full_pathname 形。spawn_error_diagnostic本体按 GNU 臂序补齐一处既有缺口:execute_cmd.c:6166-6194 的#!样本分类与 errno 无关(仅目录、不可执行、E2BIG/ENOMEM 三臂在先),解释器不可执行(EACCES)时 GNU 同样报bad interpreter: Permission denied(sys_error、126);原实现只在 ENOENT 时做样本分类,非 ENOENT 一律裸文本。此项同时修正普通命令面的同形分歧。GNU 锚点
full_pathname (command);general.c:931-943(ABSPATH 原样、否则 sh_makepath MP_DOCWD|MP_RMDOT)shell_execve;:6143 状态切换;:6150/:6156 file_error 两臂;:6184sys_error ("%s: %s: %s", command, interp, "bad interpreter");:6193 cannot-executefile_error(report_error);error.c:275-281sys_error→ error_prolog (0)本 PR 删除了什么
无文件删除、无公开 API 删除。
exec.rs三处各自的内联错误报告({}exec: {}: {}+ 裸状态切换)被共享辅助取代;spawn_error_diagnostic的 ENOENT-only 早返回被 GNU 臂序分类取代(行为差分见上)。净行数:全 PR +379/−77(回归钉 +199/−0;修法 +180/−77),净 +302 行。
验证
队长复核(二任收官)逐腿实测,日志存
~/workspace/fix-3148/:c3f27cb4):2 passed / 6 failed,红集与跑前预注册逐名一致——红恰为 6 格 exec 面分类缺陷格(基底实测形如case.sh: line 1: exec: /tmp/…/./badinterp: No such file or directory (os error 2)、rc 127),2 格回归锁(missing slash 名、not-found)基底即绿。issue3148_exec_bad_interpreter8 passed / 0 failed。RUSTFLAGS="-D warnings" cargo check --locked --lib --binsrc=0;cargo fmt --checkrc=0。