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§
- Command
Timeout Ext - Drop-in replacement for
Command::outputthat bounds the wait.
Functions§
- read_
capped 🔒 - Read
readerto EOF, retaining at mostcapbytes whenSome. - reap_
or_ kill - Wait for an already-spawned
childup totimeout, killing and reaping it if it overruns. ReturnsOk(Some(status))if it exited on its own, orOk(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 waittimeoutand an optional per-stream bytecap, killing and reaping the child on overrun. - suppress_
console - Stop Windows from allocating a console window for a console-subsystem child.
- wait_
until 🔒 - Poll
childuntil it exits ordeadlinepasses. On overrun the child is killed and reaped (so it can’t linger as a zombie) andOk(None)is returned; otherwiseOk(Some(status)).