mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 07:27:46 +00:00
Handle SIGPIPE correctly and autogenerate main() for each util
This commit is contained in:
parent
6998949c06
commit
fd555c6d21
2 changed files with 15 additions and 0 deletions
|
@ -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
13
src/uucore/panic.rs
Normal 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)
|
||||||
|
}));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue