Repository navigation
fix(timeout,nohup,nice): execvp-form child resolution for non-PE targets (#1587) - #1588
Conversation
…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.
队长复核判词稿 — WinuxCmd PR #1588(修 #1587,未发布)判词:PASS(无作者侧前置),附 1 项 Owed(§8)。 卷宗: 证据
红腿定性:base-red(逐名对照,非 PR 回归)
Owed 1 项(不阻断合入)script-chain 解释器的 argv 多一 token: 合入条件按卷宗 §7:master 前移时 re-update-branch 并重算交集 → 合入正文用 |
…#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.
|
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):
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. |
…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.
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,nohupandniceresolved children with a CreateProcess-shaped extension allow-list: any existing target without a.exe/.com/.cmd/.batextension — a shebang script,.js,.ps1, an npm/pnpm-style extensionless shim — exited 126 silently. The new shared chain inrust2/crates/winux-cmds/src/childproc.rs(extracted fromtimeout.rs; the wave4b module shape — PR #1577 carried only the gen-cases graft to main, sonohup.rs/childproc.rsland here) resolves likeexecvp:.cmd/.bat→ COMSPEC (cmd /d /s /c "...");MZmagic → 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);/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;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):timeout 5 ./hi.sh(#!/bin/sh)hi, rc 0hi, rc 0failed to run command 'X': No such file or directory... 'X': No such file or directory(kernel ENOENT)... 'X': Permission denied#!(./x.js, plain text)Exec format error*Exec format errortimeout 1 sleep 5* 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 reportsExec format errorinstead. 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_entryrequired the slash after the drive letter (C++childproc.cppmis_drive_form), so/bin/shis no longer mangled intoB:in\sh; andnicerides the shared chain (build_child_commandkeeps its CREATE_SUSPENDED ordering, #1359) so its non-PE children get the same fix.nohuplands on main with its spawn family —-hnow rejects like GNU (invalid option -- 'h', rc 125, probed).Verification
rust2/target/probe-1587/repro-matrix.sh— hi.sh →hirc 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 -nargv shapes; absolute path; bare name resolving to a.cmdon PATH; directory 126;#!/usr/bin/env shchain via a__RUBASH_SHELL_ROOTfixture (batchenv.batinterpreter →sh→ script, rc 0).timeout38 GNU + 3 win,nohup21 GNU + 7 win,nice21 GNU — all GREEN; 15 new rows (tm31–tm41, nh25–nh28) ingate/gen-cases.py; ledgerrust2/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-cmds489 green;cargo fmt --checkclean.