Skip to content

Commit

Permalink
restore the default SIGPIPE behavior as a temporary workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Aug 27, 2017
1 parent 208c11a commit 252dd97
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ env_logger = { version = "0.4", default-features = false }
grep = { version = "0.1.5", path = "grep" }
ignore = { version = "0.2.2", path = "ignore" }
lazy_static = "0.2"
libc = "0.2"
log = "0.3"
memchr = "1"
memmap = "0.5"
Expand Down
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod worker;
pub type Result<T> = result::Result<T, Box<Error + Send + Sync>>;

fn main() {
reset_sigpipe();
match Args::parse().map(Arc::new).and_then(run) {
Ok(0) => process::exit(1),
Ok(_) => process::exit(0),
Expand Down Expand Up @@ -329,3 +330,22 @@ fn eprint_nothing_searched() {
applied a filter you didn't expect. \
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
}

0 comments on commit 252dd97

Please sign in to comment.