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.
This commit is contained in:
parent
5bbc4c507a
commit
f9ec97b007
2 changed files with 5 additions and 8 deletions
10
src/lib.rs
10
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
|
// `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.
|
// 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() {
|
let mut quit_rx = data.quit_rx().unwrap_or(finish_rx);
|
||||||
(quit_rx, true)
|
|
||||||
} else {
|
|
||||||
(finish_rx, false)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut fds = [
|
let mut fds = [
|
||||||
PollFd::from_borrowed_fd(server_fd, PollFlags::IN),
|
PollFd::from_borrowed_fd(server_fd, PollFlags::IN),
|
||||||
|
|
@ -155,8 +151,8 @@ pub fn main(data: impl RunData) -> Option<()> {
|
||||||
ready = true;
|
ready = true;
|
||||||
}
|
}
|
||||||
if !fds[4].revents().is_empty() {
|
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}");
|
error!("Xwayland exited early with {status}");
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ impl Drop for Fixture {
|
||||||
let thread = unsafe { ManuallyDrop::take(&mut self.thread) };
|
let thread = unsafe { ManuallyDrop::take(&mut self.thread) };
|
||||||
// Sending anything to the quit receiver to stop the main loop. Then we guarantee a main
|
// 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
|
// 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");
|
thread.join().expect("Main thread panicked");
|
||||||
rustix::process::kill_process(self.pid, Signal::Term).unwrap();
|
rustix::process::kill_process(self.pid, Signal::Term).unwrap();
|
||||||
rustix::process::waitpid(Some(self.pid), WaitOptions::NOHANG).unwrap();
|
rustix::process::waitpid(Some(self.pid), WaitOptions::NOHANG).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue