Skip to main content

Module proc

Module proc 

Source
Expand description

Run external commands with a hard timeout.

std::process::Command::output() blocks until the child exits with no upper bound. The OS-integration probes (pmset, powercfg, xprop, gsettings, gdbus, systemd-inhibit) run inside ~10s detection poll loops and on the break-overlay open path, so a wedged tool — an unresponsive X server, a dead session bus — would stall the calling thread forever and freeze the guard flag (DND / camera / video) at its last value. CommandTimeoutExt::output_timeout bounds the wait and kills the child if it overruns, degrading to a probe error the callers already treat as “signal absent”.

Constants§

POLL_INTERVAL 🔒
How often to check whether the child has exited while waiting. 10 ms is fine-grained next to the timeouts and poll loops it guards, and keeps the wait off a busy spin.
PROBE_TIMEOUT
Upper bound for a single detection probe. The tools normally answer in well under 100 ms; 2 s is comfortably above any healthy run while still far below the poll cadence it guards, so a hung probe costs one slow tick rather than a permanently stuck signal.
READ_CHUNK 🔒
Scratch buffer size for the draining read loop.

Traits§

CommandTimeoutExt
Drop-in replacement for Command::output that bounds the wait.

Functions§

read_capped 🔒
Read reader to EOF, retaining at most cap bytes when Some.
reap_or_kill
Wait for an already-spawned child up to timeout, killing and reaping it if it overruns. Returns Ok(Some(status)) if it exited on its own, or Ok(None) if it was killed for exceeding the timeout. Either way the child is reaped, so a fire-and-forget caller can’t leak a zombie or a runaway process.
spawn_and_capture 🔒
Spawn cmd, capture its output bounded by the wait timeout and an optional per-stream byte cap, killing and reaping the child on overrun.
suppress_console
Stop Windows from allocating a console window for a console-subsystem child.
wait_until 🔒
Poll child until it exits or deadline passes. On overrun the child is killed and reaped (so it can’t linger as a zombie) and Ok(None) is returned; otherwise Ok(Some(status)).