diff --git a/Cargo.lock b/Cargo.lock index c24c3a599..469adcfb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,6 +175,7 @@ dependencies = [ "lazy_static", "libc", "lscolors", + "nix", "normpath", "num_cpus", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index c89b2e97a..674772f47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ features = ["suggestions", "color", "wrap_help"] [target.'cfg(unix)'.dependencies] users = "0.11.0" +nix = "0.23.0" [target.'cfg(all(unix, not(target_os = "redox")))'.dependencies] libc = "0.2" diff --git a/src/exit_codes.rs b/src/exit_codes.rs index 2225667db..e44111bb8 100644 --- a/src/exit_codes.rs +++ b/src/exit_codes.rs @@ -1,5 +1,8 @@ use std::process; +#[cfg(unix)] +use nix::sys::signal::{raise, signal, SigHandler, Signal}; + #[derive(Debug, Clone, Copy, PartialEq)] pub enum ExitCode { Success, @@ -26,6 +29,16 @@ impl ExitCode { /// Exit the process with the appropriate code. pub fn exit(self) -> ! { + #[cfg(unix)] + if self == ExitCode::KilledBySigint { + // Get rid of the SIGINT handler, if present, and raise SIGINT + unsafe { + if signal(Signal::SIGINT, SigHandler::SigDfl).is_ok() { + let _ = raise(Signal::SIGINT); + } + } + } + process::exit(self.into()) } }