@@ -44,12 +44,12 @@ pub mod thread_parker;
44
44
pub mod time;
45
45
46
46
#[ cfg( target_os = "espidf" ) ]
47
- pub fn init ( argc : isize , argv : * const * const u8 ) { }
47
+ pub fn init ( argc : isize , argv : * const * const u8 , _sigpipe : u8 ) { }
48
48
49
49
#[ cfg( not( target_os = "espidf" ) ) ]
50
50
// SAFETY: must be called only once during runtime initialization.
51
51
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
52
- pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
52
+ pub unsafe fn init ( argc : isize , argv : * const * const u8 , sigpipe : u8 ) {
53
53
// The standard streams might be closed on application startup. To prevent
54
54
// std::io::{stdin, stdout,stderr} objects from using other unrelated file
55
55
// resources opened later, we reopen standards streams when they are closed.
@@ -61,8 +61,9 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
61
61
// want!
62
62
//
63
63
// Hence, we set SIGPIPE to ignore when the program starts up in order
64
- // to prevent this problem.
65
- reset_sigpipe ( ) ;
64
+ // to prevent this problem. Add `#[unix_sigpipe = "..."]` above `fn main()` to
65
+ // alter this behavior.
66
+ reset_sigpipe ( sigpipe) ;
66
67
67
68
stack_overflow:: init ( ) ;
68
69
args:: init ( argc, argv) ;
@@ -151,9 +152,25 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
151
152
}
152
153
}
153
154
154
- unsafe fn reset_sigpipe ( ) {
155
+ unsafe fn reset_sigpipe ( # [ allow ( unused_variables ) ] sigpipe : u8 ) {
155
156
#[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" , target_os = "horizon" ) ) ) ]
156
- rtassert ! ( signal( libc:: SIGPIPE , libc:: SIG_IGN ) != libc:: SIG_ERR ) ;
157
+ {
158
+ // We don't want to add this as a public type to libstd, nor do we want to
159
+ // duplicate the code, so we choose to include this compiler file like this.
160
+ mod sigpipe {
161
+ include ! ( "../../../../../compiler/rustc_session/src/config/sigpipe.rs" ) ;
162
+ }
163
+
164
+ let handler = match sigpipe {
165
+ sigpipe:: INHERIT => None ,
166
+ sigpipe:: SIG_IGN => Some ( libc:: SIG_IGN ) ,
167
+ sigpipe:: SIG_DFL => Some ( libc:: SIG_DFL ) ,
168
+ _ => unreachable ! ( ) ,
169
+ } ;
170
+ if let Some ( handler) = handler {
171
+ rtassert ! ( signal( libc:: SIGPIPE , handler) != libc:: SIG_ERR ) ;
172
+ }
173
+ }
157
174
}
158
175
}
159
176
0 commit comments