exit_code.rs
This file
Path
src/util/exit_code.rs
22 lines · 743 bytes · Rust
Last changed by
Move exit code function to separate fileDavid Peterbefore adoptionb658e20
History of this fileTake it
Move exit code function to separate fileDavid Peterbefore adoptionb658e20
lines 1–22why, one step back1use std::process::ExitStatus;23#[cfg(unix)]4pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {5 use std::os::unix::process::ExitStatusExt;67 // From the ExitStatus::code documentation:8 //9 // "On Unix, this will return None if the process was terminated by a signal."10 //11 // In that case, ExitStatusExt::signal should never return None.12 //13 // To differentiate between "normal" exit codes and signals, we are using a technique14 // similar to bash (https://tldp.org/LDP/abs/html/exitcodes.html) and add 128 to the15 // signal value.16 status.code().or_else(|| status.signal().map(|s| s + 128))17}1819#[cfg(not(unix))]20pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {21 status.code()22}