From f9ec97b007547ad80147404335ed22e880dbd69d Mon Sep 17 00:00:00 2001 From: En-En <39373446+En-En-Code@users.noreply.github.com> Date: Sat, 15 Mar 2025 01:25:00 +0000 Subject: [PATCH] Make Fixture::drop send a valid exit code ptr to the stream Found a good way to avoid both an extra function to RunData and make calling `xwayland_exit_code` in other RunData types *less* prone to memory violations. Having a function with a non-empty default implementation being overridden by an empty implementation felt too awkward. --- src/lib.rs | 10 +++------- tests/integration.rs | 3 ++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cc95dbe..d7df3ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,11 +133,7 @@ pub fn main(data: impl RunData) -> Option<()> { // `finish_rx` only writes the status code of `Xwayland` exiting, so it is reasonable to use as // the UnixStream of choice when not running the integration tests. - let (mut quit_rx, is_test_thread) = if let Some(quit_rx) = data.quit_rx() { - (quit_rx, true) - } else { - (finish_rx, false) - }; + let mut quit_rx = data.quit_rx().unwrap_or(finish_rx); let mut fds = [ PollFd::from_borrowed_fd(server_fd, PollFlags::IN), @@ -155,8 +151,8 @@ pub fn main(data: impl RunData) -> Option<()> { ready = true; } if !fds[4].revents().is_empty() { - if !is_test_thread { - let status = xwayland_exit_code(&mut quit_rx); + let status = xwayland_exit_code(&mut quit_rx); + if *status != ExitStatus::default() { error!("Xwayland exited early with {status}"); } return None; diff --git a/tests/integration.rs b/tests/integration.rs index 540b94d..f54af29 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -89,7 +89,8 @@ impl Drop for Fixture { let thread = unsafe { ManuallyDrop::take(&mut self.thread) }; // Sending anything to the quit receiver to stop the main loop. Then we guarantee a main // thread does not use file descriptors which outlive the Fixture's BorrowedFd - self.quit_tx.write_all(&1_usize.to_ne_bytes()).unwrap(); + let return_ptr = Box::into_raw(Box::new(0_usize)) as usize; + self.quit_tx.write_all(&return_ptr.to_ne_bytes()).unwrap(); thread.join().expect("Main thread panicked"); rustix::process::kill_process(self.pid, Signal::Term).unwrap(); rustix::process::waitpid(Some(self.pid), WaitOptions::NOHANG).unwrap();