Skip to content

Commit f198cdb

Browse files
test(crasht): fix CentOS SIGPIPE tests (#1233)
Co-authored-by: morrisonlevi <[email protected]>
1 parent 31cf340 commit f198cdb

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

bin_tests/src/modes/unix/test_001_sigpipe.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use crate::modes::behavior::{
2525
use datadog_crashtracker::CrashtrackerConfiguration;
2626
use libc;
2727
use nix::sys::socket;
28-
use std::io::prelude::*;
29-
use std::os::unix::net::UnixStream;
28+
use std::os::unix::io::AsRawFd;
3029
use std::path::{Path, PathBuf};
3130
use 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

bin_tests/src/modes/unix/test_005_sigpipe_sigstack.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use crate::modes::behavior::{
1616
use datadog_crashtracker::CrashtrackerConfiguration;
1717
use libc;
1818
use nix::sys::socket;
19-
use std::io::prelude::*;
20-
use std::os::unix::net::UnixStream;
19+
use std::os::unix::io::AsRawFd;
2120
use std::path::{Path, PathBuf};
2221
use std::sync::atomic::AtomicPtr;
2322

@@ -72,17 +71,22 @@ fn inner(output_dir: &Path, filename: &str) -> anyhow::Result<()> {
7271
let ofile = atom_to_clone(&OUTPUT_FILE)?;
7372

7473
// Cause a SIGPIPE to occur by opening a socketpair, closing the read side, and writing into
75-
// the write side.
74+
// the write side. Use raw write() syscall to bypass Rust's MSG_NOSIGNAL protection.
7675
let (reader_fd, writer_fd) = socket::socketpair(
7776
socket::AddressFamily::Unix,
7877
socket::SockType::Stream,
7978
None,
8079
socket::SockFlag::empty(),
8180
)?;
8281
drop(reader_fd);
83-
let mut writer = UnixStream::from(writer_fd);
84-
if writer.write_all(b"Hello").is_ok() {
85-
anyhow::bail!("Expected write to fail, but it succeeded");
82+
83+
// Use raw write() syscall instead of Rust's write_all() to avoid MSG_NOSIGNAL
84+
let writer_raw_fd = writer_fd.as_raw_fd();
85+
let write_result =
86+
unsafe { libc::write(writer_raw_fd, b"Hello".as_ptr() as *const libc::c_void, 5) };
87+
88+
if write_result != -1 {
89+
anyhow::bail!("Expected write to fail with SIGPIPE, but it succeeded");
8690
}
8791

8892
// Now check the output file. Strongly assumes that nothing happened to change the value of

0 commit comments

Comments
 (0)