diff --git a/reverie-ptrace/Cargo.toml b/reverie-ptrace/Cargo.toml index a6ab723..3a97567 100644 --- a/reverie-ptrace/Cargo.toml +++ b/reverie-ptrace/Cargo.toml @@ -13,6 +13,7 @@ anyhow = "1.0.86" async-trait = "0.1.71" bincode = "1.3.3" bytes = { version = "1.6.0", features = ["serde"] } +close-err = "1.0.2" futures = { version = "0.3.30", features = ["async-await", "compat"] } goblin = "0.5.2" iced-x86 = "1.17.0" diff --git a/reverie-ptrace/src/tracer.rs b/reverie-ptrace/src/tracer.rs index b02987c..28f8acd 100644 --- a/reverie-ptrace/src/tracer.rs +++ b/reverie-ptrace/src/tracer.rs @@ -16,6 +16,7 @@ use std::path::PathBuf; use std::sync::Arc; use anyhow::Context; +use close_err::Closable; use futures::future; use futures::future::BoxFuture; use futures::future::Either; @@ -592,13 +593,13 @@ where // panicking, etc). We make a best-effort attempt to solve some of these issues. match unsafe { unistd::fork() }.expect("unistd::fork failed") { ForkResult::Child => { - drop(read1); - drop(read2); + read1.close()?; + read2.close()?; if capture_output { unistd::dup2(write1.as_raw_fd(), 1).map_err(from_nix_error)?; unistd::dup2(write2.as_raw_fd(), 2).map_err(from_nix_error)?; - drop(write1); - drop(write2); + write1.close()?; + write2.close()?; } init_tracee(events.has_rdtsc()).expect("init_tracee failed"); @@ -625,8 +626,8 @@ where let guest_pid = Pid::from(child); let child = Running::new(guest_pid); - drop(write1); - drop(write2); + write1.close()?; + write2.close()?; let stdout = read1.into(); let stderr = read2.into(); diff --git a/tests/basics.rs b/tests/basics.rs index 5ab221f..ded63f4 100644 --- a/tests/basics.rs +++ b/tests/basics.rs @@ -17,6 +17,7 @@ use std::os::fd::AsRawFd; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; +use close_err::Closable; #[allow(unused_imports)] use nix::sys::wait; #[allow(unused_imports)] @@ -267,7 +268,7 @@ fn child_should_inherit_fds() { let msg: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]; match unsafe { unistd::fork() } { Ok(ForkResult::Parent { child, .. }) => { - drop(fdwrite); + fdwrite.close().expect("close failed"); let mut buf: [u8; 8] = [0; 8]; assert_eq!(unistd::read(fdread.as_raw_fd(), &mut buf), Ok(8)); assert_eq!(buf, msg); @@ -276,7 +277,7 @@ fn child_should_inherit_fds() { unreachable!(); } Ok(ForkResult::Child) => { - drop(fdread); + fdread.close().expect("close failed"); assert_eq!(unistd::write(&fdwrite, &msg), Ok(8)); unsafe { libc::syscall(libc::SYS_exit_group, 0) }; unreachable!();