Skip to main content

bynk/
shell.rs

1//! Child-process exit statuses — shared by `dev` and `deploy`, which run
2//! `wrangler` (#2998 removed the shelled `bynkc` they once shared with).
3
4/// Map a child's [`std::process::ExitStatus`] to a process exit byte. A normal exit
5/// propagates the code. Signal death is *not* uniformly a clean stop: a
6/// shared Ctrl-C (SIGINT) is — the terminal delivered it to us too — but a
7/// SIGSEGV or the OOM killer's SIGKILL is a real failure, and mapping it to
8/// success made a crashed child read as passing in CI. Non-SIGINT
9/// signals exit \`128 + signal\`, the shell convention.
10pub fn exit_status_byte(status: &std::process::ExitStatus) -> u8 {
11    if let Some(code) = status.code() {
12        return code.clamp(0, 255) as u8;
13    }
14    #[cfg(unix)]
15    {
16        use std::os::unix::process::ExitStatusExt;
17        if let Some(sig) = status.signal() {
18            // SIGINT is 2 on every Unix.
19            if sig == 2 {
20                return 0;
21            }
22            return 128u8.saturating_add(sig.clamp(0, 127) as u8);
23        }
24    }
25    1
26}