Repository navigation
fix(tail): report dead pids on non-Windows via kill(pid, 0) (Refs #1637) - #1668
Conversation
The non-Windows Pid stub always returned false, so the follow loop never saw a dead --pid writer and follow_with_dead_writer_terminates_like_gnu hung forever off Windows. Implement kill(pid, 0) with the same rule the Windows arm documents (alive on success or EPERM), raw extern, zero crates, in the isatty style of test_cmd.rs; --pid is capped at i32::MAX so the cast cannot wrap. Adds two direct Pid nails (dead pid / own pid).
Captain review: PASSReviewed head MechanismRoot cause confirmed: Pins
CI — two reds, both ruled not this PR's (captain-corroborated from the failed logs)
Intersection / merge notes
|
fix(tail): report dead pids on non-Windows via kill(pid, 0) (Refs #1637)
Summary
follow_with_dead_writer_terminates_like_gnuhangs forever onnon-Windows: the non-Windows
sys::Pidstub always returnedfalsefrom
dead(), so the follow loop never saw a dead--pidwriter andnever exited. The Windows product and CI are unaffected.
The fix implements a real non-Windows liveness check in
rust2/crates/winux-cmds/src/tail/sys.rs(non-Windowsimp::Pid,+51/−4, one file):
kill(pid, 0)with GNU's rule — alive on successor EPERM (exists but unsignalable), dead on any other failure. This is
the same rule the Windows arm documents (
ERROR_ACCESS_DENIEDis itsEPERM), so
--pidnow terminates the follow loop on every platformonce the writer is gone. Raw
extern "C"declaration, zero crates, inthe
isattystyle oftest_cmd.rs(no libc dependency);--pidiscapped at i32::MAX by the argument parser, so the cast cannot wrap.
Two direct regression nails in
tail::sys::tests: a definitely-deadpid (i32::MAX, the same value the follow test uses as DEAD) reports
dead, and the own pid reports alive. Both are platform-independent —
they also pin the Windows arm.
GNU semantics
POSIX
kill(pid, 0): ESRCH = no such process, EPERM = alive butunsignalable. Oracle check on this machine (GNU coreutils 9.4):
tail -f --pid=2147483647 fprints the file and exits rc=0 at once.The in-tree comment at
sys.rsalready records the rule ("GNU'skill(pid, 0) treats EPERM as alive") for the Windows arm; this change
applies the same rule to the non-Windows arm.
Verification
pid_dead_for_nonexistent_pid/pid_alive_for_own_pid, compiled standalone withrustc --teston the exact file: base (HEAD35f48641) 1passed / 1 failed (
pid_dead_for_nonexistent_pidFAILED —fail-first); head 2 passed / 0 failed.
cargo test -p winux-cmds --target x86_64-pc-windows-gnu --no-runon the rebased head: rc=0, 0 errors, test binary produced; the
binary contains
pid_dead_for_nonexistent_pid,pid_alive_for_own_pidandfollow_with_dead_writer_terminates_like_gnu. My code adds zerowarnings (the sys.rs warnings in the log are pre-existing:
unused
FILE_TYPE_PIPE, and theGetFileInformationByHandle/OpenProcessredeclarations already filed as tail/sys.rs FFI redeclarations conflict with du.rs/who.rs signatures (-D warnings hygiene) #1638).rustfmt --edition 2021 --checkclean on the touched file.cargo test -p winux-cmdstarget does not compile on main (32 pre-existing errors in ~30
modules, zero in tail files — ungated
std::os::windowsimportsand stale literals; the crate's CI
rust-testsjob runs onWindows only), so the follow test could not be executed on Linux
locally; the follow test's execution leg is the Windows CI
rust-testsrun on this PR. No user-visible text changes, so noi18n catalog update is needed (AGENTS.md §i18n).
What this PR deletes
dead() -> falsebody is replaced by the realcheck; no product code path, test, or document is removed.
Refs #1637