Expand description
Cross-platform process-management primitives.
Wire historically called pgrep + kill directly, which gave us
“unsupported platform” rot on Windows. v0.7.3 funnels every
liveness check / command-line search / SIGTERM through this module
so the Windows daemon + relay paths get the same teardown +
respawn behavior the Linux + macOS paths have always had.
§Helpers
process_alive— “is pidstill around?” find_processes_by_cmdline—pgrep -f <pattern>equivalentkill_process— SIGTERM / SIGKILL equivalent (taskkill /T on Windows so the tree dies, not just the parent)
Each helper returns conservative defaults on tool failure (empty
Vec, false) so callers can chain them without aborting an upgrade
mid-flight when one query hiccups.
§Bounded shell-out (#284.1)
Every Windows shell-out below is wrapped in run_with_timeout.
PowerShell’s Get-CimInstance can wedge — observed on a host with
254 stale wire.exe processes piled up by a broken SessionStart
loop, but also any corrupted CIM repository — and any wire status
/ wire up / wire doctor call that lands on a wedged enumeration
would block forever waiting on the child. The wrapper kills the
child after WIRE_PLATFORM_TIMEOUT_SECS (default 5s) and the
caller falls through to its existing tool-error fallback (empty
Vec, None, etc.), so a probe that can’t answer in 5s reads as
“no answer” rather than “wedge the whole CLI”.
Functions§
- current_
exe_ resolved - Resolve the path of the currently-running executable, robust to the Linux
kernel’s
(deleted)marker. - find_
processes_ by_ cmdline pgrep -f <pattern>equivalent: every pid whose command line containspattern. Empty Vec on tool error or zero matches.- kill_
process - Signal a pid to exit. Returns true on successful dispatch (NOT on
confirmed exit — poll
process_alivefor that).force=trueis SIGKILL /taskkill /F;force=falseis SIGTERM /taskkill(graceful). - machine_
id_ raw - Raw, stable machine identifier bytes for the same-machine attestation
fingerprint (RFC-001 amendment #182,
same_machine::machine_fingerprint). - os_
user_ id_ bytes - Stable per-OS-user identifier bytes — the salt that keeps two different
users on one shared host (same
machine_id) from cross-pairing (#182 §S1). - parse_
session_ arg - Parse
--session <name>from a wire daemon command line. ReturnsNoneif not present. v0.14.2 (#170 supervisor pairs a--session <name>arg with the WIRE_HOME the daemon serves; this extracts it for orphan-pid diagnostic display). - pid_
cmdline - Return the command line of a specific pid, or
Noneif the pid is missing / unreadable / exited between query and answer. - process_
alive - True iff pid is alive.
- run_
with_ timeout - Run
cmdwith a wall-clock timeout. ReturnsSome(Output)on completion, orNoneon timeout (or spawn failure / wait failure). On timeout the child is killed best-effort via a platform-native shell-out (taskkill /F /T /PIDon Windows,kill -9on POSIX) so the wedged process tree exits with the wrapper. - strip_
deleted_ suffix - Pure inner of
current_exe_resolved: strip a trailing(deleted)kernel marker from an exe path. Only the exact trailing(deleted)token (leading space included) is removed — a path that merely contains the text, or a real filename ending in(deleted)without the kernel’s leading space, is left untouched. Testable without an actually-unlinked binary.