diff options
| author | varkor <github@varkor.com> | 2018-04-10 23:55:41 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-04-11 11:05:13 +0100 |
| commit | 7ab31f6556c2cce433695b113f53d6275edd724d (patch) | |
| tree | 80f61c1d771a22701a2fe3791541ff0372f58125 | |
| parent | 4b9b70c394e7f341b4016fce4cbf763d404b26f9 (diff) | |
| download | rust-7ab31f6556c2cce433695b113f53d6275edd724d.tar.gz rust-7ab31f6556c2cce433695b113f53d6275edd724d.zip | |
Prevent EPIPE causing ICEs in rustc and rustdoc
| -rw-r--r-- | src/librustc_driver/lib.rs | 12 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 4 | ||||
| -rw-r--r-- | src/rustc/rustc.rs | 5 |
4 files changed, 19 insertions, 3 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 6f88b0aecb6..4f23c62ab06 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -548,6 +548,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<PathBuf>, Option<PathBuf>) { 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 42e87f88fd4..1e51f45f149 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -101,6 +101,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 9bdea945ea4..c1298e5040d 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 9fa33f911a1..c07fb41d13b 100644 --- a/src/rustc/rustc.rs +++ b/src/rustc/rustc.rs @@ -22,4 +22,7 @@ extern {} extern crate rustc_driver; -fn main() { rustc_driver::main() } +fn main() { + rustc_driver::set_sigpipe_handler(); + rustc_driver::main() +} |
