Skip to content

exec: classify bad interpreter on the exec builtin face via shell_execve (Refs #3148) - #3214

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3148-wave1
Nov 11, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3148-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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 a line 1: segment GNU omits #2755 已修)。
  • 报告名直接用解析后的 program 显示形,session-cwd 锚定保留了 join 的 /./,而 GNU 在 builtins/exec.def:172 先以 full_pathname(general.c:931,cwd 拼合 + MP_RMDOT)重绑报告名。

修法

  • exec 面三处报告点统一走共享辅助 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 锚点

  • builtins/exec.def:172 full_pathname (command);general.c:931-943(ABSPATH 原样、否则 sh_makepath MP_DOCWD|MP_RMDOT)
  • execute_cmd.c:6126 shell_execve;:6143 状态切换;:6150/:6156 file_error 两臂;:6184 sys_error ("%s: %s: %s", command, interp, "bad interpreter");:6193 cannot-execute
  • error.c:126-129 file_error(report_error);error.c:275-281 sys_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/:

  • 基底 fail-first(钉移植到干净基底树 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_interpreter 8 passed / 0 failed。
  • lib 双边:头 1206 passed / 0 failed / 4 ignored,基底 1206 passed / 0 failed / 4 ignored,失败名集两边同为空集(头首跑曾出 112 红,复跑干净窗口归零,裁定为环境/负载 flap,名集与裁定记录在车道 REPORT)。
  • 邻茎全绿:issue2755_bad_interpreter_prolog 3/0、issue2661_exec_directory_classification 5/0、issue2696_hash_relative_spelling 2/0、issue2717_command_v_slash_qualification 3/0。
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0;cargo fmt --check rc=0。
  • GNU 探针:八格期望即 GNU bash 5.3.20 oracle 逐字输出(钉文件头注),修法锚点全部对回 execute_cmd.c / exec.def / error.c 源码行。

…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
@caomengxuan666 caomengxuan666 changed the title fix(exec): classify bad interpreter on the exec builtin face via shell_execve (Refs #3148) exec: classify bad interpreter on the exec builtin face via shell_execve (Refs #3148) Nov 11, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 11, 2026 11:28
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