1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-05 15:37:47 +00:00

Handle SIGPIPE correctly and autogenerate main() for each util

This commit is contained in:
Alex Lyon 2017-12-07 19:40:55 -08:00 committed by Roy Ivy III
parent 6998949c06
commit fd555c6d21
2 changed files with 15 additions and 0 deletions

View file

@ -7,6 +7,8 @@ mod macros;
#[macro_use] #[macro_use]
pub mod coreopts; pub mod coreopts;
pub mod panic;
#[cfg(feature = "fs")] #[cfg(feature = "fs")]
pub mod fs; pub mod fs;
#[cfg(feature = "utf8")] #[cfg(feature = "utf8")]

13
src/uucore/panic.rs Normal file
View file

@ -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::<String>() {
if res.contains("Broken pipe") {
return;
}
}
hook(info)
}));
}