Skip to main content

Module platform

Module platform 

Source
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

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 contains pattern. 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_alive for that). force=true is SIGKILL / taskkill /F; force=false is 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. Returns None if 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 None if the pid is missing / unreadable / exited between query and answer.
process_alive
True iff pid is alive.
run_with_timeout
Run cmd with a wall-clock timeout. Returns Some(Output) on completion, or None on timeout (or spawn failure / wait failure). On timeout the child is killed best-effort via a platform-native shell-out (taskkill /F /T /PID on Windows, kill -9 on 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.