Skip to content

fix(tail): report dead pids on non-Windows via kill(pid, 0) (Refs #1637) - #1668

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1637-tail-pid-dead-nonwindows
Nov 14, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1637-tail-pid-dead-nonwindows

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(tail): report dead pids on non-Windows via kill(pid, 0) (Refs #1637)

Summary

follow_with_dead_writer_terminates_like_gnu hangs forever on
non-Windows: the non-Windows sys::Pid stub always returned false
from dead(), so the follow loop never saw a dead --pid writer and
never 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-Windows imp::Pid,
+51/−4, one file): kill(pid, 0) with GNU's rule — alive on success
or EPERM (exists but unsignalable), dead on any other failure. This is
the same rule the Windows arm documents (ERROR_ACCESS_DENIED is its
EPERM), so --pid now terminates the follow loop on every platform
once the writer is gone. Raw extern "C" declaration, zero crates, in
the isatty style of test_cmd.rs (no libc dependency); --pid is
capped at i32::MAX by the argument parser, so the cast cannot wrap.

Two direct regression nails in tail::sys::tests: a definitely-dead
pid (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 but
unsignalable. Oracle check on this machine (GNU coreutils 9.4):
tail -f --pid=2147483647 f prints the file and exits rc=0 at once.
The in-tree comment at sys.rs already records the rule ("GNU's
kill(pid, 0) treats EPERM as alive") for the Windows arm; this change
applies the same rule to the non-Windows arm.

Verification

  • New nails pid_dead_for_nonexistent_pid /
    pid_alive_for_own_pid, compiled standalone with
    rustc --test on the exact file: base (HEAD 35f48641) 1
    passed / 1 failed
    (pid_dead_for_nonexistent_pid FAILED —
    fail-first); head 2 passed / 0 failed.
  • cargo test -p winux-cmds --target x86_64-pc-windows-gnu --no-run
    on the rebased head: rc=0, 0 errors, test binary produced; the
    binary contains pid_dead_for_nonexistent_pid,
    pid_alive_for_own_pid and
    follow_with_dead_writer_terminates_like_gnu. My code adds zero
    warnings (the sys.rs warnings in the log are pre-existing:
    unused FILE_TYPE_PIPE, and the GetFileInformationByHandle /
    OpenProcess redeclarations already filed as tail/sys.rs FFI redeclarations conflict with du.rs/who.rs signatures (-D warnings hygiene) #1638).
  • rustfmt --edition 2021 --check clean on the touched file.
  • Limits, stated honestly: the Linux cargo test -p winux-cmds
    target does not compile on main (32 pre-existing errors in ~30
    modules, zero in tail files — ungated std::os::windows imports
    and stale literals; the crate's CI rust-tests job runs on
    Windows only), so the follow test could not be executed on Linux
    locally; the follow test's execution leg is the Windows CI
    rust-tests run on this PR. No user-visible text changes, so no
    i18n catalog update is needed (AGENTS.md §i18n).

What this PR deletes

  • Nothing. The stub's dead() -> false body is replaced by the real
    check; no product code path, test, or document is removed.

Refs #1637

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).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review: PASS

Reviewed head ec41a866 (base 8be156e3). One file: rust2/crates/winux-cmds/src/tail/sys.rs (+51/−4 incl. 2 nails). No FAIL findings.

Mechanism

Root cause confirmed: follow.rs:544 exits the follow loop only via writer_dead = pid.as_mut().is_some_and(|p| p.dead()), and the old non-Windows dead() returned false unconditionally — --pid=<dead> could never terminate the loop. The fix stores the pid and calls raw kill(pid, 0): alive on success or EPERM, dead on any other errno. Reviewer re-probed GNU tail 9.4 (tail -f --pid=2147483647 f exits rc=0 at once; live pid still follows), and confirmed EPERM-vs-ESRCH as nobody (kill -0 1 → EPERM). --pid parser caps at i32::MAX; pid 0 is filtered to None. Sole consumer of Pid in the crate is follow.rs. rustfmt --check on head sys.rs: rc=0.

Pins

  • Two nails in tail::sys::tests: pid_dead_for_nonexistent_pid (i32::MAX) and pid_alive_for_own_pid — both ok by name on Windows CI, suite 754 passed; 0 failed.
  • Fail-first: base binary 1 pass / 1 fail (rc=101, pid_dead_for_nonexistent_pid FAILED); head binary 2/2 ok. Statically proven too — the base stub is literally false (sys-base.rs:391-393), so the nail cannot pass on base. The reviewer's own standalone rustc --test reproduction never ran (write wall EDQUOT for ~35 min); not a blocker given the static proof + lane base-binary log + CI head green by name.
  • Follow test follow_with_dead_writer_terminates_like_gnu (8 cells, DEAD = --pid=2147483647) also ok on Windows CI. The PR took the issue's better option (real check, not cfg-gating the test).
  • Windows cross-compile: cargo test -p winux-cmds --target x86_64-pc-windows-gnu --no-run rc=0; 93 ^warning lines all pre-existing in the untouched Windows arm (incl. the GetFileInformationByHandle/OpenProcess redeclarations that belong to tail/sys.rs FFI redeclarations conflict with du.rs/who.rs signatures (-D warnings hygiene) #1638). The PR adds zero warnings.
  • Linux cargo test does not compile (33 errors, zero in any tail file — du/xargs/timeout/numfmt/mkfifo/join); CI rust-tests is Windows-only, so the Windows run is the execution leg.

CI — two reds, both ruled not this PR's (captain-corroborated from the failed logs)

Intersection / merge notes

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 10:00
@caomengxuan666
caomengxuan666 merged commit 0195c57 into main Nov 14, 2026
14 of 16 checks passed
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