]> git.lizzy.rs Git - rust.git/commitdiff
Prevent EPIPE causing ICEs in rustc and rustdoc
authorvarkor <github@varkor.com>
Tue, 10 Apr 2018 22:55:41 +0000 (23:55 +0100)
committervarkor <github@varkor.com>
Wed, 11 Apr 2018 10:05:13 +0000 (11:05 +0100)
src/librustc_driver/lib.rs
src/librustdoc/lib.rs
src/libstd/sys/unix/mod.rs
src/rustc/rustc.rs

index 6f88b0aecb6b674e935619c37aecb9b6be3ae9b5..4f23c62ab0663eb9754f0ed56474372b0a7818eb 100644 (file)
@@ -548,6 +548,18 @@ macro_rules! do_or_return {($expr: expr, $sess: expr) => {
     (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));
index 42e87f88fd40d475b5b7143511ff3a6c47817f4e..1e51f45f149a0873fc57b49acb89582e3c7624f9 100644 (file)
@@ -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 || {
index 9bdea945ea42eacf52a993f91f6912bcbb675a08..c1298e5040dbeec35b3a503c17d1aa2e4aa961c8 100644 (file)
@@ -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() {}
 }
 
index 9fa33f911a1686f8118a3f31bbf6dde38578d653..c07fb41d13b5ca149ccbd87bd1480f33ab1d32b7 100644 (file)
@@ -22,4 +22,7 @@
 
 extern crate rustc_driver;
 
-fn main() { rustc_driver::main() }
+fn main() {
+    rustc_driver::set_sigpipe_handler();
+    rustc_driver::main()
+}