From 68c2706780031e3aac6cccea0f7b867ad5eff13a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 26 Mar 2014 14:34:52 -0700 Subject: native: Ignore SIGPIPE by default 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 --- src/libstd/libc.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 42221f07449..7496428f672 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -266,6 +266,8 @@ pub mod types { } pub enum timezone {} + + pub type sighandler_t = size_t; } pub mod bsd44 { use libc::types::os::arch::c95::{c_char, c_int, c_uint}; @@ -637,6 +639,8 @@ pub mod types { } pub enum timezone {} + + pub type sighandler_t = size_t; } pub mod bsd44 { use libc::types::os::arch::c95::{c_char, c_int, c_uint}; @@ -1206,6 +1210,8 @@ pub mod types { } pub enum timezone {} + + pub type sighandler_t = size_t; } pub mod bsd44 { @@ -2292,6 +2298,8 @@ pub mod consts { use libc::types::os::arch::c95::{c_int, size_t}; pub static SIGTRAP : c_int = 5; + pub static SIGPIPE: c_int = 13; + pub static SIG_IGN: size_t = 1; pub static GLOB_ERR : c_int = 1 << 0; pub static GLOB_MARK : c_int = 1 << 1; @@ -2741,6 +2749,8 @@ pub mod consts { use libc::types::os::arch::c95::{c_int, size_t}; pub static SIGTRAP : c_int = 5; + pub static SIGPIPE: c_int = 13; + pub static SIG_IGN: size_t = 1; pub static GLOB_APPEND : c_int = 0x0001; pub static GLOB_DOOFFS : c_int = 0x0002; @@ -3136,6 +3146,8 @@ pub mod consts { use libc::types::os::arch::c95::{c_int, size_t}; pub static SIGTRAP : c_int = 5; + pub static SIGPIPE: c_int = 13; + pub static SIG_IGN: size_t = 1; pub static GLOB_APPEND : c_int = 0x0001; pub static GLOB_DOOFFS : c_int = 0x0002; @@ -3838,6 +3850,24 @@ pub mod funcs { } } + pub mod signal { + use libc::types::os::arch::c95::c_int; + use libc::types::os::common::posix01::sighandler_t; + + #[cfg(not(target_os = "android"))] + extern { + pub fn signal(signum: c_int, + handler: sighandler_t) -> sighandler_t; + } + + #[cfg(target_os = "android")] + extern { + #[link_name = "bsd_signal"] + pub fn signal(signum: c_int, + handler: sighandler_t) -> sighandler_t; + } + } + pub mod wait { use libc::types::os::arch::c95::{c_int}; use libc::types::os::arch::posix88::{pid_t}; -- cgit 1.4.1-3-g733a5