Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit on broken pipe #279

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ bitflags = "1.0.4"
timer = "0.2.0"
chrono = "0.4"
crossbeam = "0.7.3"
libc = "0.2"

[features]
default = []
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ impl Skim {
}

pub fn filter(options: &SkimOptions, source: Option<SkimItemReceiver>) -> i32 {
reset_sigpipe();

let output_ending = if options.print0 { "\0" } else { "\n" };
let query = options.filter;
let default_command = match env::var("SKIM_DEFAULT_COMMAND").as_ref().map(String::as_ref) {
Expand Down Expand Up @@ -314,3 +316,26 @@ impl Skim {
}
}
}

// Following is quoted from ripgrep's commit history:
// @ https://github.com/BurntSushi/ripgrep/commit/3065a8c9c839f7e722a73e8375f2e41c7e084737
// """
// 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
}