Skip to content

fix(timeout,nohup,nice): execvp-form child resolution for non-PE targets (#1587) - #1588

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/timeout-execvp-1587
Nov 12, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/timeout-execvp-1587

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1587 (WinuxCmd 2.0 / rust2 wave — the 1.x C++ spawner keeps its own tracking; this lane touches only the rust2 tree).

What

timeout, nohup and nice resolved children with a CreateProcess-shaped extension allow-list: any existing target without a .exe/.com/.cmd/.bat extension — a shebang script, .js, .ps1, an npm/pnpm-style extensionless shim — exited 126 silently. The new shared chain in rust2/crates/winux-cmds/src/childproc.rs (extracted from timeout.rs; the wave4b module shape — PR #1577 carried only the gen-cases graft to main, so nohup.rs/childproc.rs land here) resolves like execvp:

  1. as given → PATHEXT variants → PATH search (unchanged native chain);
  2. the hit is classified: .cmd/.bat → COMSPEC (cmd /d /s /c "..."); MZ magic → native image; #! → [interpreter, optional-arg, script, ...argv] with the interpreter resolved recursively (binfmt_script.c value model: first space/tab splits, ONE optional arg, CR kept — a CRLF shebang misses its interpreter, probed ENOENT);
  3. a POSIX-rooted spelling the native chain missed (/bin/sh, /usr/bin/env) resolves through the product's shell-namespace mapper (winux-core::path::shell_tree_to_native), then through its leaf name on PATH;
  4. a file with neither magic is the execvp ENOEXEC analog: 126 Exec format error (C-locale GNU wording, byte-probed under WSL coreutils 9.4; ASCII quotes like the rest of the product's diagnostics).

Diagnostics follow the measured GNU shapes (WSL coreutils 9.4, rust2/target/probe-1587/gnu-probe*.sh):

case GNU (probed) WinuxCmd 2.0 now
timeout 5 ./hi.sh (#!/bin/sh) hi, rc 0 hi, rc 0
missing command 127 failed to run command 'X': No such file or directory same
shebang with missing interpreter 127 ... 'X': No such file or directory (kernel ENOENT) same
directory operand 126 ... 'X': Permission denied same
found file, no MZ/#! (./x.js, plain text) 126 Exec format error* 126 Exec format error
timeout 1 sleep 5 124 124

* glibc's execvp additionally retries ENOEXEC through /bin/sh (probed: a text file "runs", an empty file exits 0 under WSL GNU). That is a libc extension, not execvp/kernel semantics; per the issue contract WinuxCmd reports Exec format error instead. Association-run scripts (.js/.ps1 with no shebang) are the same class — GNU-on-msys launches them through Windows associations, which pure execvp resolution cannot; they now get the diagnostic instead of silence.

Also fixed in passing (same extraction): normalize_entry required the slash after the drive letter (C++ childproc.cppm is_drive_form), so /bin/sh is no longer mangled into B:in\sh; and nice rides the shared chain (build_child_command keeps its CREATE_SUSPENDED ordering, #1359) so its non-PE children get the same fix. nohup lands on main with its spawn family — -h now rejects like GNU (invalid option -- 'h', rc 125, probed).

Verification

  • Repro matrix (issue + shebang variants + PATHEXT edges), driver-run: rust2/target/probe-1587/repro-matrix.sh — hi.sh → hi rc 0; hi.cmd rc 0; no-such 127 + message; timeout 1 sleep 5 = 124; x.js/x.ps1/plain 126 + Exec format error; extensionless shim rc 0; #!/bin/echo / #!/bin/echo -n argv shapes; absolute path; bare name resolving to a .cmd on PATH; directory 126; #!/usr/bin/env sh chain via a __RUBASH_SHELL_ROOT fixture (batch env.bat interpreter → sh → script, rc 0).
  • Gate: timeout 38 GNU + 3 win, nohup 21 GNU + 7 win, nice 21 GNU — all GREEN; 15 new rows (tm31–tm41, nh25–nh28) in gate/gen-cases.py; ledger rust2/target/gate/ledger.tsv (e.g. tm31 rc(r/g/c)=3/3/126 — the script's exit status now propagates on the rust side while C++ still shows the old silent 126).
  • cargo test -p winux-cmds 489 green; cargo fmt --check clean.

…ets (#1587)

GNU contract (probed WSL coreutils 9.4, rust2/target/probe-1587/): execvp
runs shebang scripts through their interpreter and reports every launch
failure — 127 "No such file or directory" for a missing command AND for a
missing shebang interpreter (the kernel's ENOENT), 126 "Exec format error"
for a found file no format can run, 126 "Permission denied" for a
directory. WinuxCmd 2.0's spawners exited 126 silently for shebang
scripts, .js/.ps1 files and extensionless shims (the issue's repro:
`timeout 5 ./hi.sh` -> rc 126 with an empty stderr; now prints hi, rc 0).

childproc.rs (extracted from timeout.rs on the wave4b shape, now the
shared spawner module) owns the resolution chain: as given -> PATHEXT
variants -> PATH search -> classify the hit. A .cmd/.bat routes through
COMSPEC; MZ magic is a native image; a `#!` file launches
[interpreter, optional-arg, script, ...argv] with the interpreter
resolved recursively (binfmt_script.c value model: first space/tab splits
the line, the remainder is ONE optional argument with trailing space/tab
trimmed, a CR kept so a CRLF shebang misses -> ENOENT, probed). A
POSIX-rooted spelling the native chain missed (`/bin/sh`, `/usr/bin/env`)
resolves through winux-core's shell-namespace mapper
(shell_tree_to_native), then through its leaf name on PATH — the same
accommodation the file commands make. A file with neither magic is the
execvp ENOEXEC analog -> 126 "Exec format error" (C-locale wording,
probed). A bare interpreter name is cwd-relative (kernel open()
semantics; probed "#!env sh" -> 127), never a PATH search; a missing
interpreter maps to ENOENT/127 against the script operand (probed:
`timeout 5 ./x` with `#!/bin/no-such-interp` -> 127 "No such file or
directory"), refining the issue's "Exec format error" sketch to the
measured GNU shape.

timeout.rs/nohup.rs/nice.rs consume the chain (spawn_child;
build_child_command for nice's CREATE_SUSPENDED, #1359). nohup lands on
main with its spawn family (wave4b left the module unmerged; PR #1577
carried only the gen-cases graft) — its non-PE children had the same
silent 126. `nohup -h` rejects like GNU ("invalid option -- 'h'", rc 125,
probed) ahead of argopt's bare -h -> help mapping; the `--` consumption,
POSIXLY_CORRECT 125/127 and no-permutation surfaces ride unchanged.

Documented boundary: glibc's execvp retries an ENOEXEC file through
/bin/sh (probed: a plain text file "runs" and an empty file exits 0
under WSL GNU); that fallback is a libc extension, not execvp or kernel
semantics — WinuxCmd reports "Exec format error" instead, per the issue
contract. Association-run scripts (.js/.ps1 with no shebang) are the
same class: 126 with the diagnostic, not the msys association launch.

Port fidelity: normalize_entry now requires the slash after the drive
letter (childproc.cppm is_drive_form) so "/bin/sh" is not mangled into
"B:in\sh" — the pre-extraction rust port dropped that guard.

Gate: timeout 38 GNU + 3 win, nohup 21 GNU + 7 win, nice 21 GNU — all
GREEN with 15 new rows (tm31-41, nh25-28; ledger
rust2/target/gate/ledger.tsv). cargo test 489 green, fmt clean.
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核判词稿 — WinuxCmd PR #1588(修 #1587,未发布)

判词:PASS(无作者侧前置),附 1 项 Owed(§8)。 卷宗:~/workspace/review-winx-1588/CAPTAIN-VERIFY.md。以下数字均为复核员亲核(头 c465868a,base c2fa3db0),非车道自报。

证据

  • Issue 契约全兑:shebang 脚本经解释器启动(timeout 5 ./hi.sh → hi rc 0);缺失命令 127 + failed to run command 'X': No such file or directory;无格式文件 126 Exec format error;目录操作数 126 Permission denied;timeout 1 sleep 5 = 124。诊断映射在 timeout/nohup 两处逐字同构。
  • CI 13/14 通过或跳过:baseline / compare / oracle / i18n-drift / arm64 双腿 / x64-full / GNU master differential 全部绿;唯一红腿 build-windows (x64, default) 的 ctest 23 败已定性为 base-red(见下)。
  • Gate:timeout 38 GNU + 3 win、nohup 21 GNU + 7 win、nice 21 GNU 全绿(CI compare/oracle/baseline 三腿佐证);15 新行 tm31–tm41 / nh25–nh28 在 tsv 与 gen-cases.py 三处一致。
  • 单元钉:childproc 11 个(含 shebang 双 token、CRLF 命中不到、缺失解释器、裸解释器 cwd 限定、PE 优先、batch spawn rc 7)+ timeout/nohup 各自的 127/126 措辞钉;CI Rust tests 腿在 Windows 上跑过且绿。
  • 卫生:本地 rustfmt --check 对 5 个改动 Rust 文件全过;base == master 头,交集 ∅。

红腿定性:base-red(逐名对照,非 PR 回归)

Owed 1 项(不阻断合入)

script-chain 解释器的 argv 多一 token:childproc.rs 的 Script 臂在 inner(末位已是内层脚本路径)之后又推一次 interpreter,内层脚本在 argv 里出现两次,后续参数移位。内核实测(探针 ~/workspace/review-winx-1588/probe-chain-argv.sh):外层 #!/…/inner.sh -x、内层 #!/bin/sh -e 时 sh 应见 [sh, -e, inner2, -x, outer2, A, B]。单层 shebang 不受影响,基底对此形是静默 126,故不判 FAIL。修复为删 argv.push(interpreter); 一行 + 补链式单元钉;另附 parse_shebang_line 的 line_end >= HEAD_BYTES 死条件改法。合入后由队长另立 follow-up(草案在卷宗附录 A)。

合入条件

按卷宗 §7:master 前移时 re-update-branch 并重算交集 → 合入正文用 merge-body.md 逐字内容(含补的删除节)→ 注意 #1589 与本 PR 同碰 5 个核心文件(建议 #1588 先合,#1589 其后 rebase,最终顺序由队长定)→ 合入后由队长立 §8 follow-up 并核 #1587 已关。

…#1587)

Resolve the #1588/#1589 overlap per the captain's union protocol
(~/workspace/review-winx-1588/UNION-PROTOCOL.md): the four code files
take #1588's version wholesale, lib.rs takes the union of both sides'
registrations, nohup.tsv/timeout.tsv take #1588's versions, gen-cases.py
takes the auto-merge result.

gen-cases.py dedup (captain-confirmed, MERGE-REPORT.md §10): drop the
duplicate shadowed second nohup_rows definition (24 rows, wave4b version)
so emit regenerates the committed 28-row nohup.tsv (nh25-nh28 kept);
the other duplicate *_rows groups are pre-existing master warts,
untouched.

Verified at union time: emit consistent (all TSVs byte-identical to
committed); old ChildResolve struct-variant Found { path, batch } zero;
lib.rs nine commands' pub mod + registrations each exactly once;
rustfmt --check clean on the five changed Rust files; cargo check
-p winux-cmds --lib --target x86_64-pc-windows-gnu green.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CI-red triage for this PR's build-windows (x64 default) job, per the serial-retry gate's "real regression" flag — verdict: all 23 failures are inherited from main; zero are caused by this PR (external users waiting on #1587: the fix itself is sound and live on main).

Evidence (checked in the prescribed order):

  1. Merge-base (6fc5ebf) run — main's own CI run 43245017935, which tested exactly the merge-base — fails the byte-identical 23-set ("99% tests passed, 23 tests failed out of 3840", same names/order). Base red ⇒ inherited.
  2. main's tip run (c74112c, 43286004339) fails the same 23. The streak started at the wiring wave3a: touch/ln/stat/seq/tee/paste/fold/fmt -> rust2 dispatch (#1488) #1570 wave3a wiring merge (5b22542, 21 cases), seq.seq_precision_ignores_last_operand joined at the #1488 borrow uutils algorithms #1575 borrow-algo merge (6f3146e), the sixth head timeout at #1488 wave4a #1576 wave4a (e30adb3). Last green main run: 1c407e1 (Nov 11 18:13).
  3. This PR's diff (git diff 6fc5ebf7..b6ee44d0 --stat) touches only childproc.rs/nohup.rs/timeout.rs/nice.rs/lib.rs + gate cases — no overlap with any failing family, no causal chain.
  4. seq: confirmed the #1488 borrow uutils algorithms #1575 hypothesis — the test joined exactly at the #1488 borrow uutils algorithms #1575 merge; the borrow-algo gate's 33 seq cases never covered the t>prec rendering shape.

Disposition: the 23 are wave3a/4a regressions on main; the root causes are small and local, so they are fixed in passing on a follow-up branch — #1600 (seq exact-decimal grid bug, rust2 FIFO bridge for tee/paste, ln symlink target verbatim, stat %c/%S/--cached/%F, tac test synced to the GNU close_stdout shape that b1cf94c pinned). All GNU 9.4-probed; the 23-case slice runs 100% green locally.

caomengxuan666 added a commit that referenced this pull request Nov 13, 2026
…mlink

The wave3a CI triage commit (3d1739a) fixed the issue1367 readbacks by
stopping the api_path absolutize on the symlink TARGET, but it dropped
the whole target pipeline with it: run 43342952034 regressed 3 ln unit
tests that main tip passes —

  ln.ln_symlink_dot_slash_target_resolves_natively
  ln.ln_symlink_forward_slash_path_target_resolves_natively
  ln.ln_symlink_drive_dialect_lands_on_operand_drive

CI (privileged, so the skip branch does not mask these) stored the raw
operand text "./original.txt" in the reparse point: the '/'-free assert
failed and the Win32 path parser refuses forward-slash reparse text with
ERROR_INVALID_NAME, so the read through the link came back empty.

GNU symlink(2) takes the operand verbatim, but this boundary is a pinned
[DIFFERS]: the 1.x ln.cpp:733 contract folds BOTH operands through
normalize_api_operand (drive dialect "/e/..." -> "E:\...", #1234) and
then runs win32_normalize_symlink_target (win32.cppm:112, '/' -> '\',
#1101) on the text that reaches CreateSymbolicLinkW. Neither step
absolutizes, so the issue1367 verbatim-relative fix keeps standing.

Restore exactly that contract: symlink_target_text() = normalize_operand
fold chain + separator replace (relative and already-native operands pass
through unchanged), feed it to CreateSymbolicLinkW; the LINK operand
keeps api_path. New unit pin symlink_target_text_pins holds all five
shapes (relative plain, dot-slash, forward-slash path, already-native,
/cygdrive and /d/ dialect folds).

Local: cargo test 549 green; ln 29, head/mkfifo/seq/tac/stat/tee/paste 59
and readlink/realpath/stat-symlink 120 unit tests green. The symlink
creation asserts themselves still skip on this host (no
SeCreateSymbolicLinkPrivilege, no Developer Mode) — the pin test carries
the verification the CI run confirms.

Refs #1488, #1588, #1600.
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.

timeout: non-PE targets exit 126 with an empty stderr (no diagnostic)

1 participant