Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions bin_tests/src/modes/unix/test_001_sigpipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use crate::modes::behavior::{
use datadog_crashtracker::CrashtrackerConfiguration;
use libc;
use nix::sys::socket;
use std::io::prelude::*;
use std::os::unix::net::UnixStream;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::sync::atomic::AtomicPtr;

Expand Down Expand Up @@ -81,17 +80,22 @@ fn inner(output_dir: &Path, filename: &str) -> anyhow::Result<()> {
let ofile = atom_to_clone(&OUTPUT_FILE)?;

// Cause a SIGPIPE to occur by opening a socketpair, closing the read side, and writing into
// the write side.
// the write side. Use raw write() syscall to bypass Rust's MSG_NOSIGNAL protection.
let (reader_fd, writer_fd) = socket::socketpair(
socket::AddressFamily::Unix,
socket::SockType::Stream,
None,
socket::SockFlag::empty(),
)?;
drop(reader_fd);
let mut writer = UnixStream::from(writer_fd);
if writer.write_all(b"Hello").is_ok() {
anyhow::bail!("Expected write to fail, but it succeeded");

// Use raw write() syscall instead of Rust's write_all() to avoid MSG_NOSIGNAL
let writer_raw_fd = writer_fd.as_raw_fd();
let write_result =
unsafe { libc::write(writer_raw_fd, b"Hello".as_ptr() as *const libc::c_void, 5) };

if write_result != -1 {
anyhow::bail!("Expected write to fail with SIGPIPE, but it succeeded");
Comment on lines +91 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed offline moving this into its own function, and adding a test that it does indeed raise a SIGPIPE. Followup work since this PR is needed to unblock CI.

}

// Now check the output file. Strongly assumes that nothing happened to change the value of
Expand Down
16 changes: 10 additions & 6 deletions bin_tests/src/modes/unix/test_005_sigpipe_sigstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use crate::modes::behavior::{
use datadog_crashtracker::CrashtrackerConfiguration;
use libc;
use nix::sys::socket;
use std::io::prelude::*;
use std::os::unix::net::UnixStream;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::sync::atomic::AtomicPtr;

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

// Cause a SIGPIPE to occur by opening a socketpair, closing the read side, and writing into
// the write side.
// the write side. Use raw write() syscall to bypass Rust's MSG_NOSIGNAL protection.
let (reader_fd, writer_fd) = socket::socketpair(
socket::AddressFamily::Unix,
socket::SockType::Stream,
None,
socket::SockFlag::empty(),
)?;
drop(reader_fd);
let mut writer = UnixStream::from(writer_fd);
if writer.write_all(b"Hello").is_ok() {
anyhow::bail!("Expected write to fail, but it succeeded");

// Use raw write() syscall instead of Rust's write_all() to avoid MSG_NOSIGNAL
let writer_raw_fd = writer_fd.as_raw_fd();
let write_result =
unsafe { libc::write(writer_raw_fd, b"Hello".as_ptr() as *const libc::c_void, 5) };

if write_result != -1 {
anyhow::bail!("Expected write to fail with SIGPIPE, but it succeeded");
}

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