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.rs53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index 9771b057d8d..2e89becfa67 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -8,14 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![allow(missing_docs)]
-#![allow(non_camel_case_types)]
+#![allow(missing_docs, bad_style)]
 
 use io::{self, ErrorKind};
 use libc;
 use num::One;
 use ops::Neg;
-use alloc::oom;
 
 #[cfg(target_os = "android")]   pub use os::android as platform;
 #[cfg(target_os = "bitrig")]    pub use os::bitrig as platform;
@@ -46,25 +44,10 @@ pub mod thread_local;
 pub mod time;
 pub mod stdio;
 
-// A nicer handler for out-of-memory situations than the default one. This one
-// prints a message to stderr before aborting. It is critical that this code
-// does not allocate any memory since we are in an OOM situation. Any errors are
-// ignored while printing since there's nothing we can do about them and we are
-// about to exit anyways.
-fn oom_handler() -> ! {
-    use intrinsics;
-    let msg = "fatal runtime error: out of memory\n";
-    unsafe {
-        libc::write(libc::STDERR_FILENO,
-                    msg.as_ptr() as *const libc::c_void,
-                    msg.len() as libc::size_t);
-        intrinsics::abort();
-    }
-}
-
-#[cfg(not(any(target_os = "nacl", test)))]
+#[cfg(not(test))]
 pub fn init() {
-    use libc::signal;
+    use alloc::oom;
+
     // By default, some platforms will send a *signal* when an 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
@@ -73,15 +56,33 @@ pub fn init() {
     // 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);
+        reset_sigpipe();
     }
 
     oom::set_oom_handler(oom_handler);
-}
 
-#[cfg(all(target_os = "nacl", not(test)))]
-pub fn init() {
-    oom::set_oom_handler(oom_handler);
+    // A nicer handler for out-of-memory situations than the default one. This
+    // one prints a message to stderr before aborting. It is critical that this
+    // code does not allocate any memory since we are in an OOM situation. Any
+    // errors are ignored while printing since there's nothing we can do about
+    // them and we are about to exit anyways.
+    fn oom_handler() -> ! {
+        use intrinsics;
+        let msg = "fatal runtime error: out of memory\n";
+        unsafe {
+            libc::write(libc::STDERR_FILENO,
+                        msg.as_ptr() as *const libc::c_void,
+                        msg.len() as libc::size_t);
+            intrinsics::abort();
+        }
+    }
+
+    #[cfg(not(target_os = "nacl"))]
+    unsafe fn reset_sigpipe() {
+        assert!(libc::signal(libc::SIGPIPE, libc::SIG_IGN) != !0);
+    }
+    #[cfg(target_os = "nacl")]
+    unsafe fn reset_sigpipe() {}
 }
 
 pub fn decode_error_kind(errno: i32) -> ErrorKind {