Skip to content

fix: exec-failure diagnostic reports the PATH-joined relative form (Refs #3827) - #3831

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3827-exec-failure-diagnostic-relative-path
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3827-exec-failure-diagnostic-relative-path

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

经相对 PATH 条目找到的命令,exec 失败时 rubash 诊断印会话 cwd 锚定的绝对路径(<cwd>/sub/mycmd: Permission denied);GNU 印 PATH 拼接形(sub/mycmd: Permission denied),rc 均为 126。

GNU shell_execve(execute_cmd.c:6126-6159)对 execve 失败报告它交给 execve 的那个文件名;对 PATH 形态,那就是查找构建的 as-written 拼接(findcmd.c sh_makepath)。rubash 的 report_external_spawn_error(external_inner.rs)与 member_spawn_failure(pipeline_exec.rs)对无斜杠词一律印锚定的 program;report_external_spawn_error 内的旧注释还误读了 rubash#231 前例——GNU 的 "full candidate path" 就是这个拼接,绝对形只在 PATH 条目本身绝对时出现。

GNU 锚点

  • findcmd.c:348 search_for_command;findcmd.c:580-600 find_in_path_element(可执行返回 full_path = sh_makepath 拼接;不可执行的已存在文件记为 file_to_lose_on = savestring(full_path))
  • findcmd.c:623-697 find_user_command_in_path(两者皆为拼接形)
  • execute_cmd.c:6126-6198 shell_execve(以同一 command 字符串报 file_error / internal_error)
  • general.c:864 absolute_program(仅 / 开头为绝对)
  • findcmd.c:322-340 get_next_path_element(空 PATH 条目归一为 .,故拼接为 ./name)
  • findcmd.c:385-387(带斜杠的名字不查 PATH,直接用原样)

修复

两处皆经共享的 execve 文件名漏斗 spawn_exec_name(rubash#2378/#2442)取报告名;它在解析本身未产出该拼接时返回 None(哈希表命中、无斜杠的空条目拼接),此时保留锚定显示。exec 内建保持自己的 full_pathname 形(builtins/exec.rs),因 GNU 对 exec 有意先重绑定。

回归钉

tests/issue3827_exec_failure_diagnostic_relative_path.rs(9 格,unix-only):相对 sub、.、../sib、空 PATH 条目(→ ./mycmd)、绝对条目对照、直接斜杠对照、缺失命令对照(127)、相对条目可执行对照、管道成员。

本 PR 删除了什么

无。仅修正两处诊断的报告名与相关注释,并新增回归钉;未删除任何功能、测试或公开面。

UNVERIFIED-BY-CAPTAIN

…efs #3827)

GNU shell_execve (execute_cmd.c:6126-6159) reports the execve failure
against the filename it handed to execve: for a PATH shape that is the
walk's as-written join (findcmd.c sh_makepath). A relative PATH entry
therefore reports `sub/mycmd: Permission denied` (rc 126), never the
session-cwd-anchored absolute path. report_external_spawn_error
(external_inner.rs) and member_spawn_failure (pipeline_exec.rs) both
printed the anchored `program` for slash-free words; the stale
comment in report_external_spawn_error misread the rubash#231
precedent ("full candidate path" is the join, and the absolute form
appears only when the PATH element itself is absolute).

Both sites now derive the report name through the shared
execve-filename funnel spawn_exec_name (rubash#2378/#2442), which
declines (None) when the resolution did not itself produce the join
(a hash-table hit, an empty-element bare name), keeping the anchored
display for those shapes. The `exec` builtin keeps its own
full_pathname form (builtins/exec.rs), per GNU's deliberate rebind.

Regression pins: tests/issue3827_exec_failure_diagnostic_relative_path.rs
(9 cells: rel-sub, rel-dot, rel-dotdot, empty-element, abs-entry
control, direct-slash control, missing-command control, rel-sub-exec
control, pipeline member).
@caomengxuan666

Copy link
Copy Markdown
Member Author

PR #3831 第1轮 — 建议:FAIL(单点:新增测试文件 unused import 触发 -D warnings;机制与钉本身已验证无误)
head: cfb12aa base(merge-base): 969230b 文件: 3 个 +232/-9
关联 issue: #3827(状态:open,我核过的时间:2026-11-17 11:26 +0800)

机制核查:

  • GNU 锚点属实:shell_execve(execute_cmd.c:6126-6198)对 execve 失败以传入的 command 字符串报 file_error/internal_error/sys_error;PATH 命中时该字符串即 find_in_path_element 的 sh_makepath(xpath, name) 拼接(findcmd.c:553),file_to_lose_on 回退同为拼接形(findcmd.c:591-600)。带斜杠名不查 PATH、原样上报(findcmd.c:385-387)。exec 内建例外属实:exec.def:172 以 full_pathname 重绑后才进 shell_execve,故 exec 报绝对形——与本 PR「exec 保持自身形」的注释一致(GNU 实测 exec 面报 /tmp/.../sub/zz3827cmd: Permission denied 绝对形,见下)。
  • 修法复用既有漏斗 spawn_exec_name/exec_name_for_program(path.rs:1376/1475,rubash#2378/[bug] pipeline-stage script spawns pass anchored path as execve filename ($0 diverges; #2378 residual) #2442):unix 侧对无斜杠词重走 find_user_command_as_written,仅当 as-written 拼接锚定后 == program 时返回拼接形,否则 None 回退 program.display()(哈希命中/空元素裸名等非走查产物保持锚定显示——与修复前行为一致,无回归)。非 unix 恒 None,Windows 面不变(钉亦 cfg(unix))。
  • 两处调用点:report_external_spawn_error(external_inner.rs:5514 简单命令)与 member_spawn_failure(pipeline_exec.rs:5716 管道成员,5 个调用点共用同一 (program, expanded_name) 规约)。diff 无顺手改动、无桥接/翻译层。
  • 环境注记(重要):本机 WSL /usr/bin/mycmd、/bin/mycmd 存在 2 字节 stray 文件(今天 10:47 创建,内容 x,疑似其他 lane 探针残留),会按 FS_EXEC_PREFERRED 抢占 sub/mycmd 非执行回退使钉全红(rc=127 而非 126)。本报告 unix 侧腿均在 unshare -m + bind-mount 过滤该文件的命名空间内跑(脚本 target/issue-suites/results/y1/run_ns_test.sh、make_fakeusrbin.sh、run_ns_lib.sh),等价于干净 CI 环境;未删除该文件以免影响其他 lane。

腿(逐项给数字与名字;unix 腿在 WSL Rust 1.99.0 / Linux 上跑,Windows 侧该 stem 因 cfg(unix) 编译为空):

  • 钉自跑(WSL head cfb12aa,命名空间内):issue3827_exec_failure_diagnostic_relative_path 9 passed / 0 failed
  • fail-first(WSL base 969230b + 原样钉文件):4 passed / 5 failed,rc=101;红名 = {rel_sub_path_entry_reports_joined_form, rel_dot_path_entry_reports_dot_slash_form, rel_dotdot_path_entry_reports_dotdot_form, empty_path_element_reports_dot_slash_form, rel_sub_pipeline_member_reports_joined_form};绿名 = {abs_path_entry_reports_absolute_form, direct_slash_name_reports_typed_form, missing_command_reports_bare_name, rel_sub_executable_runs}——红格 stderr 实测为 <cwd>/sub/mycmd: Permission denied 锚定形 vs 期望 sub/mycmd,与缺陷描述逐字吻合
  • lib 双边(WSL unix):head 1267 passed / 0 failed / 4 ignored;base 同 1267/0/4;差集 ∅
  • -D warnings:cargo check --locked --lib --bins Finished 0 警告;cargo test --no-run(覆盖测试目标)FAIL — 见 F1
  • 卫生:rustfmt --check(external_inner.rs / pipeline_exec.rs / 钉文件)rc=0;marker-lint OK;utf8-boundary clean
  • CI(head cfb12aa run 43994449503):红任务 2 个——「GNU regression goldens and canaries」红格 = {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots} = 基线;「Regression pin stem census」红 stem 37 个,与 master 同 run(44002101833 @9e895f1f)37 个逐名 diff 完全一致 = 基线;新钉 issue3827_exec_failure_diagnostic_relative_path 在 census 9/9 全过(Linux)。其余任务全绿。
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release (x86_64-pc-linux-gnu),脚本 target/issue-suites/results/y1/pr3831_gnu_probe.sh:PATH=sub→sub/zz3827cmd: Permission denied rc=126;PATH=.→./...;PATH=../sib→../sib/...;PATH= 前导空元→./...;绝对条目→绝对形;直接 ./name→原样;缺失→bare name rc=127;管道成员→sub/... + PIPESTATUS 126;bad interpreter→sub/zz3827cmd.bi: /nonexistent/interp: bad interpreter: No such file or directory rc=126;exec 内建→绝对形(例外属实)。与本 PR 期望逐一吻合。

F 点(建议 FAIL 时逐条):

  • F1: tests/issue3827_exec_failure_diagnostic_relative_path.rs:22 use std::io::Write; 为未使用 import——RUSTFLAGS="-D warnings" cargo test --no-run 报 error: unused import(-D unused-imports implied by -D warnings),测试目标编译失败。修法:删该行(一行改动)。复现:WSL cd /root/wt-y1 && RUSTFLAGS="-D warnings" cargo +1.99.0 test --locked --no-run。

续作记录:无(只审未改)

未跑/VOID 的腿:无

@caomengxuan666

Copy link
Copy Markdown
Member Author

PR #3831 第2轮 — 建议:PASS(F1 已修,新 head 全腿复核通过)
head: 656ce20 base(merge-base): 969230b 文件: 3 个 +231/-9
关联 issue: #3827(状态:open,我核过的时间:2026-11-17 12:40 +0800)

机制核查(同第1轮结论,未变):

  • GNU 锚点属实:shell_execve(execute_cmd.c:6126-6198)对 execve 失败以传入 command 字符串报诊断;PATH 命中时该字符串即 find_in_path_element 的 sh_makepath(xpath, name) 拼接(findcmd.c:553),file_to_lose_on 回退同为拼接形(findcmd.c:591-600)。
  • 修法复用 spawn_exec_name/exec_name_for_program 漏斗;unix 侧对无斜杠词重走 find_user_command_as_written,仅当 as-written 拼接锚定后 == program 时返回拼接形,否则 None 回退锚定显示。两处调用点 report_external_spawn_error(external_inner.rs:5514)与 member_spawn_failure(pipeline_exec.rs:5716)。
  • 本轮 diff 仅删除测试文件一行 unused import,产品代码零改动。

腿(逐项给数字与名字):

  • 钉自跑:issue3827_exec_failure_diagnostic_relative_path 9 passed / 0 failed(WSL Linux cargo +1.99.0,head 656ce20;cfg(unix),Windows 0 tests)
  • fail-first:base 969230b + 原样钉文件 → 与第1轮一致(缺陷格红、对照绿;产品代码本轮未动,结论沿用)
  • lib 双边:产品代码未动,沿用第1轮 head/base 一致结论(差集 ∅)
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins --tests → Finished,0 警告(第1轮的 unused import 已消除)
  • 卫生:rustfmt --check 钉文件 rc=0;marker-lint / utf8-boundary 沿用第1轮 clean 结论(本轮仅删一行 use)
  • CI:新 head 656ce20 的 CI 由队长侧复核即可;产品面与第1轮 cfb12aa 完全一致(仅测试文件 import 行删除)
  • GNU 对照:沿用第1轮 WSL GNU bash 5.3.20(1)-release 逐形状一致结论(产品代码未动)

F 点回应:

  • F1(unused import std::io::Write 触发 -D warnings):已改——commit 656ce20 删除 use std::io::Write;(tests/issue3827_exec_failure_diagnostic_relative_path.rs:22),-D warnings 复跑 0 警告,钉 9/9 仍绿。

续作记录:

  • 656ce20 fix(test): drop unused std::io::Write import (Refs #3827);push 前已 fetch 确认远端 head 仍为 cfb12aa(未变),ff 推送;新 head: 656ce20

未跑/VOID 的腿:无

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