Skip to content

Commit 7ab31f6

Browse files
committed
Prevent EPIPE causing ICEs in rustc and rustdoc
1 parent 4b9b70c commit 7ab31f6

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/librustc_driver/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,18 @@ fn run_compiler_impl<'a>(args: &[String],
548548
(result, Some(sess))
549549
}
550550

551+
#[cfg(unix)]
552+
pub fn set_sigpipe_handler() {
553+
unsafe {
554+
// Set the SIGPIPE signal handler, so that an EPIPE
555+
// will cause rustc to terminate, as expected.
556+
assert!(libc::signal(libc::SIGPIPE, libc::SIG_DFL) != libc::SIG_ERR);
557+
}
558+
}
559+
560+
#[cfg(windows)]
561+
pub fn set_sigpipe_handler() {}
562+
551563
// Extract output directory and file from matches.
552564
fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>) {
553565
let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o));

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct Output {
101101

102102
pub fn main() {
103103
const STACK_SIZE: usize = 32_000_000; // 32MB
104+
rustc_driver::set_sigpipe_handler();
104105
env_logger::init();
105106
let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
106107
syntax::with_globals(move || {

src/libstd/sys/unix/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ pub fn init() {
8080
reset_sigpipe();
8181
}
8282

83-
#[cfg(not(any(target_os = "emscripten", target_os="fuchsia")))]
83+
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
8484
unsafe fn reset_sigpipe() {
8585
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
8686
}
87-
#[cfg(any(target_os = "emscripten", target_os="fuchsia"))]
87+
#[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
8888
unsafe fn reset_sigpipe() {}
8989
}
9090

src/rustc/rustc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ extern {}
2222

2323
extern crate rustc_driver;
2424

25-
fn main() { rustc_driver::main() }
25+
fn main() {
26+
rustc_driver::set_sigpipe_handler();
27+
rustc_driver::main()
28+
}

0 commit comments

Comments
 (0)