about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-28 12:46:44 -0700
committerbors <bors@rust-lang.org>2014-03-28 12:46:44 -0700
commit42e1003e4a2dd4d3a7e800c2f5b99bf77a4b635e (patch)
tree5bc3863a0d3b29c53c14844a3344182986496dbe /src/libnative
parentfd4f15ea6b04fcacc8c8446c5d725c25daab0624 (diff)
parent68c2706780031e3aac6cccea0f7b867ad5eff13a (diff)
downloadrust-42e1003e4a2dd4d3a7e800c2f5b99bf77a4b635e.tar.gz
rust-42e1003e4a2dd4d3a7e800c2f5b99bf77a4b635e.zip
auto merge of #13158 : alexcrichton/rust/issue-13123, r=brson
Some unix platforms will send a SIGPIPE signal instead of returning EPIPE from a
syscall by default. The native runtime doesn't install a SIGPIPE handler,
causing the program to die immediately in this case. This brings the behavior in
line with libgreen by ignoring SIGPIPE and propagating EPIPE upwards to the
application in the form of an IoError.

Closes #13123
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/lib.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs
index 34e85a9819a..59b3437ad9a 100644
--- a/src/libnative/lib.rs
+++ b/src/libnative/lib.rs
@@ -97,6 +97,24 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
     // frames above our current position.
     let my_stack_bottom = my_stack_top + 20000 - OS_DEFAULT_STACK_ESTIMATE;
 
+    // When using libgreen, one of the first things that we do is to turn off
+    // the SIGPIPE signal (set it to ignore). 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.
+    #[cfg(windows)] fn ignore_sigpipe() {}
+    #[cfg(unix)] fn ignore_sigpipe() {
+        use std::libc;
+        use std::libc::funcs::posix01::signal::signal;
+        unsafe {
+            assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != -1);
+        }
+    }
+    ignore_sigpipe();
+
     rt::init(argc, argv);
     let mut exit_code = None;
     let mut main = Some(main);