summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJack O'Connor <oconnor663@gmail.com>2017-08-27 14:32:20 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-08-27 15:01:05 -0400
commit3065a8c9c839f7e722a73e8375f2e41c7e084737 (patch)
tree16c9eb4b40b8ddf7a1f6b26f8d6f59faac826703 /src/main.rs
parent208c11af56d4eaf81e6ea9ffaf7bfead43b9238f (diff)
restore the default SIGPIPE behavior as a temporary workaround
See https://github.com/BurntSushi/ripgrep/issues/200.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index ce49263f..73ced955 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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),
@@ -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
+}