mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-11 14:30:24 +02:00
restore the default SIGPIPE behavior as a temporary workaround
See https://github.com/BurntSushi/ripgrep/issues/200.
This commit is contained in:
committed by
Andrew Gallant
parent
208c11af56
commit
3065a8c9c8
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -10,6 +10,7 @@ dependencies = [
|
|||||||
"grep 0.1.6",
|
"grep 0.1.6",
|
||||||
"ignore 0.2.2",
|
"ignore 0.2.2",
|
||||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -38,6 +38,7 @@ env_logger = { version = "0.4", default-features = false }
|
|||||||
grep = { version = "0.1.5", path = "grep" }
|
grep = { version = "0.1.5", path = "grep" }
|
||||||
ignore = { version = "0.2.2", path = "ignore" }
|
ignore = { version = "0.2.2", path = "ignore" }
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
|
libc = "0.2"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
memchr = "1"
|
memchr = "1"
|
||||||
memmap = "0.5"
|
memmap = "0.5"
|
||||||
|
20
src/main.rs
20
src/main.rs
@ -54,6 +54,7 @@ mod worker;
|
|||||||
pub type Result<T> = result::Result<T, Box<Error + Send + Sync>>;
|
pub type Result<T> = result::Result<T, Box<Error + Send + Sync>>;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
reset_sigpipe();
|
||||||
match Args::parse().map(Arc::new).and_then(run) {
|
match Args::parse().map(Arc::new).and_then(run) {
|
||||||
Ok(0) => process::exit(1),
|
Ok(0) => process::exit(1),
|
||||||
Ok(_) => process::exit(0),
|
Ok(_) => process::exit(0),
|
||||||
@ -329,3 +330,22 @@ fn eprint_nothing_searched() {
|
|||||||
applied a filter you didn't expect. \
|
applied a filter you didn't expect. \
|
||||||
Try running again with --debug.");
|
Try running again with --debug.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Rust standard library suppresses the default SIGPIPE behavior, so that
|
||||||
|
// writing to a closed pipe doesn't kill the process. The goal is to instead
|
||||||
|
// handle errors through the normal result mechanism. Ripgrep needs some
|
||||||
|
// refactoring before it will be able to do that, however, so we re-enable the
|
||||||
|
// standard SIGPIPE behavior as a workaround. See
|
||||||
|
// https://github.com/BurntSushi/ripgrep/issues/200.
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn reset_sigpipe() {
|
||||||
|
extern crate libc;
|
||||||
|
unsafe {
|
||||||
|
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
fn reset_sigpipe() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user