Handle SIGPIPE

Based on the sample code in
https://stackoverflow.com/a/65760807/509706

Closes #28
ida_star
Wilfred Hughes 2021-08-29 16:50:05 +07:00
parent 475eb804ab
commit cc93976969
4 changed files with 21 additions and 2 deletions

@ -22,6 +22,9 @@ Fixed crashes on files with non-ASCII characters on long lines.
Removed the unused `--lang` argument.
Difftastic now handles writing to a closed pipe (SIGPIPE) gracefully
rather than crashing.
## 0.7
### Git integration

5
Cargo.lock generated

@ -102,6 +102,7 @@ dependencies = [
"diff",
"itertools",
"lazy_static",
"libc",
"pretty_assertions",
"regex",
"rustc-hash",
@ -143,9 +144,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.98"
version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
[[package]]
name = "memchr"

@ -29,6 +29,7 @@ strsim = "0.10.0"
lazy_static = "1.4.0"
atty = "0.2.14"
tree-sitter = "0.19.5"
libc = "0.2.99"
[dev-dependencies]
pretty_assertions = "0.6.1"

@ -133,7 +133,21 @@ fn parse_args() -> Mode {
}
}
/// Terminate the process if we get SIGPIPE.
#[cfg(unix)]
fn reset_sigpipe() {
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
}
#[cfg(not(unix))]
fn reset_sigpipe() {
// Do nothing.
}
fn main() {
reset_sigpipe();
configure_color();
let arena = Arena::new();