diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 3dec84d174dd8..cb91ff6a43e9c 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -547,6 +547,18 @@ fn run_compiler_impl<'a>(args: &[String], (result, Some(sess)) } +#[cfg(unix)] +pub fn set_sigpipe_handler() { + unsafe { + // Set the SIGPIPE signal handler, so that an EPIPE + // will cause rustc to terminate, as expected. + assert!(libc::signal(libc::SIGPIPE, libc::SIG_DFL) != libc::SIG_ERR); + } +} + +#[cfg(windows)] +pub fn set_sigpipe_handler() {} + // Extract output directory and file from matches. fn make_output(matches: &getopts::Matches) -> (Option, Option) { let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o)); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1339a66f8b2e9..148a57c420f8d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -100,6 +100,7 @@ struct Output { pub fn main() { const STACK_SIZE: usize = 32_000_000; // 32MB + rustc_driver::set_sigpipe_handler(); env_logger::init(); let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || { syntax::with_globals(move || { diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 9bdea945ea42e..c1298e5040dbe 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -80,11 +80,11 @@ pub fn init() { reset_sigpipe(); } - #[cfg(not(any(target_os = "emscripten", target_os="fuchsia")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))] unsafe fn reset_sigpipe() { assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR); } - #[cfg(any(target_os = "emscripten", target_os="fuchsia"))] + #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))] unsafe fn reset_sigpipe() {} } diff --git a/src/rustc/rustc.rs b/src/rustc/rustc.rs index a888838ce432c..ab5a7c3f747eb 100644 --- a/src/rustc/rustc.rs +++ b/src/rustc/rustc.rs @@ -23,4 +23,7 @@ extern {} extern crate rustc_driver; -fn main() { rustc_driver::main() } +fn main() { + rustc_driver::set_sigpipe_handler(); + rustc_driver::main() +}