@@ -25,8 +25,7 @@ use crate::modes::behavior::{
2525use datadog_crashtracker:: CrashtrackerConfiguration ;
2626use libc;
2727use nix:: sys:: socket;
28- use std:: io:: prelude:: * ;
29- use std:: os:: unix:: net:: UnixStream ;
28+ use std:: os:: unix:: io:: AsRawFd ;
3029use std:: path:: { Path , PathBuf } ;
3130use std:: sync:: atomic:: AtomicPtr ;
3231
@@ -81,17 +80,22 @@ fn inner(output_dir: &Path, filename: &str) -> anyhow::Result<()> {
8180 let ofile = atom_to_clone ( & OUTPUT_FILE ) ?;
8281
8382 // Cause a SIGPIPE to occur by opening a socketpair, closing the read side, and writing into
84- // the write side.
83+ // the write side. Use raw write() syscall to bypass Rust's MSG_NOSIGNAL protection.
8584 let ( reader_fd, writer_fd) = socket:: socketpair (
8685 socket:: AddressFamily :: Unix ,
8786 socket:: SockType :: Stream ,
8887 None ,
8988 socket:: SockFlag :: empty ( ) ,
9089 ) ?;
9190 drop ( reader_fd) ;
92- let mut writer = UnixStream :: from ( writer_fd) ;
93- if writer. write_all ( b"Hello" ) . is_ok ( ) {
94- anyhow:: bail!( "Expected write to fail, but it succeeded" ) ;
91+
92+ // Use raw write() syscall instead of Rust's write_all() to avoid MSG_NOSIGNAL
93+ let writer_raw_fd = writer_fd. as_raw_fd ( ) ;
94+ let write_result =
95+ unsafe { libc:: write ( writer_raw_fd, b"Hello" . as_ptr ( ) as * const libc:: c_void , 5 ) } ;
96+
97+ if write_result != -1 {
98+ anyhow:: bail!( "Expected write to fail with SIGPIPE, but it succeeded" ) ;
9599 }
96100
97101 // Now check the output file. Strongly assumes that nothing happened to change the value of
0 commit comments