From fd555c6d2148c52d86d83b3b816f02615fec6ece Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Thu, 7 Dec 2017 19:40:55 -0800 Subject: [PATCH] Handle SIGPIPE correctly and autogenerate main() for each util --- src/uucore/lib.rs | 2 ++ src/uucore/panic.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/uucore/panic.rs diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs index 9b1a5e763..3c6314d8a 100644 --- a/src/uucore/lib.rs +++ b/src/uucore/lib.rs @@ -7,6 +7,8 @@ mod macros; #[macro_use] pub mod coreopts; +pub mod panic; + #[cfg(feature = "fs")] pub mod fs; #[cfg(feature = "utf8")] diff --git a/src/uucore/panic.rs b/src/uucore/panic.rs new file mode 100644 index 000000000..765e035ab --- /dev/null +++ b/src/uucore/panic.rs @@ -0,0 +1,13 @@ +use std::panic; + +pub fn install_sigpipe_hook() { + let hook = panic::take_hook(); + panic::set_hook(Box::new(move |info| { + if let Some(res) = info.payload().downcast_ref::() { + if res.contains("Broken pipe") { + return; + } + } + hook(info) + })); +}