about summary refs log tree commit diff
path: root/src/libstd/sys/unix/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys/unix/mod.rs')
-rw-r--r--src/libstd/sys/unix/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index bbed42cc31d..964bc08ff4e 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -12,6 +12,7 @@
 #![allow(non_camel_case_types)]
 
 use io::{self, ErrorKind};
+use libc::funcs::posix01::signal::signal;
 use libc;
 use num::One;
 use ops::Neg;
@@ -47,6 +48,19 @@ pub mod thread_local;
 pub mod time;
 pub mod stdio;
 
+pub fn init() {
+    // By default, some platforms will send a *signal* when a EPIPE error
+    // would otherwise be delivered. This runtime doesn't install a SIGPIPE
+    // handler, causing it to kill the program, which isn't exactly what we
+    // want!
+    //
+    // Hence, we set SIGPIPE to ignore when the program starts up in order
+    // to prevent this problem.
+    unsafe {
+        assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0);
+    }
+}
+
 pub fn decode_error_kind(errno: i32) -> ErrorKind {
     match errno as libc::c_int {
         libc::ECONNREFUSED => ErrorKind::ConnectionRefused,