Skip to main content

ic_host_process/status/
mod.rs

1//! Explicit shell-style projection of observed child status; callers own CLI fallback policy.
2
3use std::process::ExitStatus;
4
5/// Return the numeric exit code, or `128 + signal` for Unix signal termination.
6///
7/// An unclassified status returns `None`. Callers choose its fallback and the
8/// conversion to their CLI's supported exit-code range. This does not wait,
9/// signal, reap or otherwise manage a process, and does not imply success.
10#[must_use]
11pub fn shell_status_code(status: ExitStatus) -> Option<i32> {
12    if let Some(code) = status.code() {
13        return Some(code);
14    }
15    #[cfg(unix)]
16    {
17        use std::os::unix::process::ExitStatusExt as _;
18        status.signal().map(|signal| 128 + signal)
19    }
20    #[cfg(not(unix))]
21    {
22        None
23    }
24}
25
26#[cfg(all(test, unix))]
27mod tests;