Skip to content

fix(exec): rebind the exec target with GNU full_pathname (Refs #3316) - #3564

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/3316-exec-full-pathname
Nov 18, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/3316-exec-full-pathname

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3316

修了什么

exec ./s.sh 的脚本内 $0 留有 /./($PWD/./s.sh),GNU 为 $PWD/s.sh。

根因:exec 内建把 会话 cwd 锚定后的 resolved program(cwd.join("./s.sh"),保留 ./)直接当 execve filename / ENOEXEC 重入的 $0;而它的失败报告名又走了另一套过度规范化(删掉所有 . 与 .. 分量)。两条都不是 GNU 的 full_pathname。

修法(src/builtins/exec.rs):一个 full_pathname() 按 GNU 逐字实现——绝对词原样;否则 cwd + "/" + 词,且只去掉一个前导 ./(MP_RMDOT),其余分量(././s、a/./s、a/../s、.//s)一律保留。它的输入词由 exec_target_word() 取自共享 spawn 漏斗 path::spawn_exec_name(带斜杠的词=原样;PATH 搜索=as-written <elem>/<name> 拼接)。这一个字符串同时用作:

  • execve filename(#! 脚本由内核把它交给解释器当 $0)——改走 external_command_for_named_program_with_exec_name(..., Some(filename));
  • ENOEXEC 重入的 $0(shell_wrapped_command 的 zero word);
  • exec 的全部失败报告名(exec_report_name、缺失路径报告)。

src/executor/path.rs 只改注释(exec 不再是"漏斗例外",而是"漏斗词再经 full_pathname")。

另:tests/d11_pipeline_squote_carrier_regressions.rs 仅 rustfmt 重排(master 上该文件未格式化,cargo fmt --check 在 master 即红;与 #3547/#3549 等同款 diff 逐字节一致)。

删了什么

full_pathname_word()(把所有 . 分量删光且在 unix 上会丢根 / 的旧实现)与 exec_report_name 里的 ./.. 文本规范化;缺失路径报告里的 .replace("/./", "/")。

GNU 依据

  • builtins/exec.def:151 取目标词(absolute_program (args[0]) ? args[0] : search_for_command (args[0], 1))
  • builtins/exec.def:172 com2 = full_pathname (command),exec.def:231 交 shell_execve
  • general.c:931-943 full_pathname():绝对词原样(937-938),否则 sh_makepath (NULL, file, MP_DOCWD|MP_RMDOT)(940)
  • lib/sh/makepath.c sh_makepath():MP_RMDOT 仅在 dir[0]=='.' && dir[1]=='/' 时跳过 2 字节;拼接时 cwd 末尾非 / 才补 /
  • execute_cmd.c:6253 ENOEXEC 重入 args[1] = command(新 $0)

GNU 5.3.20 实测(WSL /usr/local/bin/bash,脚本文件,$PWD 折成 D):exec ./s.sh→D/s.sh,exec ././s.sh→D/./s.sh,exec .//s.sh→D//s.sh,exec sub/../s.sh→D/sub/../s.sh,PATH=.:$PATH exec s.sh→D/s.sh,PATH=./sub/:$PATH exec t.sh→D/sub/t.sh;缺失:exec sub/./nope→D/sub/./nope: No such file or directory。修后 Linux 构建 17 形全部逐字节一致。

验证(逐 stem 报数)

  • 新钉 tests/issue3316_exec_full_pathname.rs
    • Linux(WSL cargo):修前 0/4,修后 4/4
    • Windows(MSVC):修前 0/1,修后 1/1(unix-only 三例 cfg 掉)
  • 相邻 stem(Linux,修后全绿):issue1037 2/2、issue1132 3/3、issue1175 2/2、issue1274 3/3、issue1459 1/1、issue1832 10/10、issue191 1/1、issue2661 5/5、issue2755 3/3、issue3148 8/8、issue3256 7/7
  • 相邻 stem(Windows):同上集合修后除 issue1132(0/3)与 issue1459(0/1)外全绿;这两个在未修 master 上同样 0/3、0/1(Windows 无 arg0 的既有失败,非本 PR 引入)
  • cargo build -j 4 干净(Windows + Linux);cargo fmt --check 干净(WSL 全树;Windows rustfmt 1.10 对改动文件 --check 干净)

Owed

  1. Windows 的 PATH 相对元素形(PATH=.:$PATH; exec s.sh)仍给 $PWD/./s.sh:非 unix 的 spawn_exec_name 返回 None,Windows 查找无 as-written 拼接,回落到 resolved program。需给 Windows PATH walk 补 as-written 记录,范围超出本 PR —— 故用 Refs 不用 Fixes。
  2. Windows 失败报告名仍是 C:/... 形(既有行为,未动)。
  3. exec '~/x'(引号内字面 ~)的 full_pathname 波浪号展开分支(general.c:935)未实现,未测。

builtins/exec.def:172 rebinds the target word with full_pathname
(general.c:931-943): an absolute word verbatim, otherwise
sh_makepath(NULL, word, MP_DOCWD|MP_RMDOT) -- the cwd, a '/', and the
word with exactly one leading "./" removed. The exec builtin instead
used the session-anchored resolved program (cwd join keeping "./") as
the execve filename and script $0, and its failure reports ran a
different, over-eager canonicalization (dropping every "." and "..").

One full_pathname helper now produces the execve filename (so a #!
script's $0), the ENOEXEC re-entry's $0, and every exec failure report
name, over the shared spawn funnel's word (path::spawn_exec_name).

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 05:25
@caomengxuan666
caomengxuan666 marked this pull request as draft November 14, 2026 05:46
Enumerate workspace target roots with cargo metadata and bound each rustfmt argv below the Windows command-line limit. Fail closed if required tooling is missing. Include the two pre-existing rustfmt wrapping corrections so the gate passes without bypasses.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 and others added 3 commits November 14, 2026 14:40
Reject missing workspace member packages, empty target sets, and targets
without source paths before launching any rustfmt batch. Malformed metadata
must not silently reduce the gate's coverage and still report success.

Preserve edition fallback, target deduplication, CLI and bounded batching.
All 15 checker tests pass; the real gate checks 1486 targets in 10 batches.

Refs #3569.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Bring the formatting-gate feature history into this draft feature branch
so follow-up commits run the normal Windows pre-commit check without the
legacy command-line overflow. This does not merge either PR into master.

Refs #3569; its review and landing remain independent.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GNU builtins/exec.def:151/172 exec_builtin rebinds the target through
general.c:931 full_pathname. general.h:264-270 ABSPATH recognizes only a
leading slash on Unix, and lib/sh/makepath.c:66 sh_makepath copies the
cwd and remaining word unchanged after stripping one leading ./.

Restrict backslash folding and DOS-drive recognition to Windows. Unix
backslashes in filenames and cwd remain ordinary bytes; D:/ is relative.
Preserve the original Windows behavior and the exec target owner.

Match the test fixture's Unix PWD to Command::current_dir, as in a real
parent shell. The distinct pre-existing stale-PWD repair defect is #3570.

New Linux pins: 4 pass/3 fail before, 7 pass after. Adjacent exec/argv0/
name diagnostics: 35 pass. Existing Windows pin: 1 pass. Full formatting
gate: 1487 targets in 11 batches.

Refs #3316, #3564.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

Full-Pathname Re-Review: Unix Regression Fixed

Pushed adcbd99b after finding three platform-spelling regressions in the
original PR head 9de1501f. Fresh GNU Bash 5.3.20 and master 8b48c164
execute the same LF case files and agree:

  • An executable containing a literal backslash runs; original PR head
    changes the byte into a separator and exits 127.
  • A cwd containing a literal backslash works; original PR head changes
    that cwd spelling and exits 127.
  • Unix relative D:/target.sh binds an absolute $0; original PR head
    misclassifies it as a Windows absolute path and leaves $0 relative.

The fix gates only the Win32 spelling rules to Windows. Unix word/cwd
bytes remain intact. Existing one-leading-./ stripping and Windows
behavior remain unchanged. No text blacklist or extra execution shim.

GNU ownership read before editing: exec.def:151/172 exec_builtin,
general.c:931-943 full_pathname, general.h:264-270 ABSPATH (only
leading / on Unix), lib/sh/makepath.c:66-124 sh_makepath.

Verification:

  • Updated-fixture Linux pin before fix: 4 pass / 3 fail, tests executed.
  • Same pin after fix: 7/7 pass.
  • Linux adjacent exec/argv0/name/diagnostic tests: 35/35 pass.
  • Existing Windows pin: 1/1 pass.
  • Normal native Windows commit hook: 1,487 roots / 11 batches, exit 0.

The Unix test fixture now exports PWD matching Command::current_dir, as a
normal parent shell does. The separate startup repair bug exposed by an
invalid inherited PWD is already present on master and reported as #3570;
no init/path subsystem changes are smuggled into this fix.

The draft feature history adopts formatting-gate prerequisite #3569 so
commits use the real Windows hook, not PATH/hook bypasses. Please review/
land #3569 first. Neither PR nor master was merged; this remains draft.

Complete raw logs and script-file probes:
target/issue-suites/results/review3316/, especially
pin-{before,after}-pwd-env.*, windows-pin-pwd-env.*,
linux-adjacent.*, fmt-pwd-env.*, and both commit-hook logs.

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】s10 lane — 建议:PENDING(CONFLICTING,跳过不合)

head: adcbd99 base(merge-base): 8b48c16 文件: 8 个 +884/-99
关联 issue: #3316(状态:open,我核过的时间:2026-11-16 20:15 CST)

处置:不合并。gh pr view 实时 mergeable=CONFLICTING / mergeStateStatus=DIRTY;对现尖 origin/master 12fb4e61 做 git merge-tree --write-tree rc=1,冲突文件两处:

  • src/builtins/exec.rs
  • scripts/git-hooks/pre-commit

按 S 波口径(DIRTY/CONFLICTING → 跳过不合,报告),本轮不做冲突消解、不推进 head。

审计中已发现、需在消解冲突时一并处理的两点(供队长/续作参考,非本轮判词):

  1. 无关面:本 PR 除了 exec.rs 的 full_pathname 修复,还新增 scripts/check-rustfmt.py(267 行)、scripts/check_rustfmt_test.py(324 行)并重写 scripts/git-hooks/pre-commit(把 cargo fmt --check 换成 python 批处理门)。这与 [bug] exec of a relative-path script leaves "/./" in $0 #3316 无因果关系,且正是冲突点之一;按「一个 PR 一件事」应拆出单独 PR。
  2. 机制方向本身与 GNU 一致(builtins/exec.def:151/172 取词 → general.c:931-943 full_pathname() 绝对词原样、否则 sh_makepath(NULL,file,MP_DOCWD|MP_RMDOT),lib/sh/makepath.c 的 MP_RMDOT 只跳前导 ./;execute_cmd.c:6253 ENOENT/ENOEXEC 重入取 command 作 $0),但那是在旧基底上的判读;消解冲突后需按现尖重跑钉与 GNU 17 形,不能沿用旧 head 的 17 形结论。

腿:本轮全部未跑(按 CONFLICTING 跳过规则),不记为通过。

未跑/VOID 的腿:

  • 钉自跑 / fail-first / lib 双边 / -D warnings / 卫生 / GNU 对照 —— 全部因 CONFLICTING 跳过,待把分支 rebase/merge 到现尖后再按第 4 节协议补齐。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3564 裁决关联说明 — 建议:PENDING(维持 s10 车道 CONFLICTING 结论;钩子方向裁决已出,全文见 #3569 最新裁决评论)

head: adcbd99(gh 实时,未变) mergeable=CONFLICTING/DIRTY

要点:

  • 本 PR 叠在 fix(tooling): batch the workspace rustfmt hook on Windows #3569 之上(git merge-base pr/3564 pr/3569 = b7086c3 = fix(tooling): batch the workspace rustfmt hook on Windows #3569 head),自带 4ffb2ba85 chore: adopt the reviewed bounded formatting gate prerequisite——钩子门取舍直接决定本 PR 的 rebase 形态。
  • exec.rs 的 full_pathname 机制方向与 GNU 一致(s10 车道已核:builtins/exec.def:151/172 取词 → general.c:931-943 full_pathname 绝对词原样/否则 sh_makepath(MP_DOCWD|MP_RMDOT) 只去一个前导 ./;execute_cmd.c:6253 ENOEXEC 重入取 command 作 $0),但该结论在旧基底上,rebase 后须按现尖重跑钉与 GNU 17 形。
  • 与 s10 车道「门文件与 [bug] exec of a relative-path script leaves "/./" in $0 #3316 无关、应拆出」的意见一致:无论钩子裁决结果如何,本 PR 的最终净形态都应只含 src/builtins/exec.rs + src/executor/path.rs + tests/issue3316_exec_full_pathname.rs。

未跑/VOID 的腿:无(纯裁决关联评论,未动代码)。

# Conflicts:
#	scripts/git-hooks/pre-commit
#	src/builtins/exec.rs
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:32
@caomengxuan666
caomengxuan666 merged commit 273cfed into master Nov 18, 2026
9 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3316-exec-full-pathname branch November 18, 2026 08:32
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