diff --git a/src/fork.rs b/src/fork.rs index 9b4799d..be87f6c 100644 --- a/src/fork.rs +++ b/src/fork.rs @@ -11,6 +11,7 @@ use std::panic::UnwindSafe; use crate::io::pipe::{self, Pipe}; use crate::syscall::SyscallStatus; +use crate::tools::Fd; pub async fn forking_syscall(func: F) -> io::Result where @@ -54,9 +55,10 @@ impl Fork { let pid = c_try!(unsafe { libc::fork() }); if pid == 0 { drop(pipe_r); - let mut pipe_w = unsafe { std::fs::File::from_raw_fd(pipe_w.into_raw_fd()) }; - + let mut pipe_w = unsafe { Fd::from_raw_fd(pipe_w.into_raw_fd()) }; let _ = std::panic::catch_unwind(move || { + pipe_w.set_nonblocking(false).unwrap(); + let mut pipe_w = unsafe { std::fs::File::from_raw_fd(pipe_w.into_raw_fd()) }; let out = match func() { Ok(SyscallStatus::Ok(val)) => Data { val, diff --git a/src/io/reactor.rs b/src/io/reactor.rs index 604a200..479318a 100644 --- a/src/io/reactor.rs +++ b/src/io/reactor.rs @@ -171,7 +171,7 @@ impl IntoRawFd for PolledFd { } impl PolledFd { - pub fn new(fd: Fd) -> io::Result { + pub fn new(mut fd: Fd) -> io::Result { fd.set_nonblocking(true).map_err(io_err_other)?; Self::new_with_reactor(fd, self::default_reactor()) } diff --git a/src/io/seq_packet.rs b/src/io/seq_packet.rs index 66e5673..1535d8b 100644 --- a/src/io/seq_packet.rs +++ b/src/io/seq_packet.rs @@ -116,7 +116,7 @@ impl SeqPacketSocket { let fd = self.fd.as_raw_fd(); self.fd.wrap_read(cx, || { - c_result!(unsafe { libc::sendmsg(fd, &mut msg.0 as *mut libc::msghdr, 0) }) + c_result!(unsafe { libc::recvmsg(fd, &mut msg.0 as *mut libc::msghdr, 0) }) .map(|rc| rc as usize) }) } diff --git a/src/tools.rs b/src/tools.rs index 76dfc41..8ed3d50 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -20,7 +20,7 @@ impl FromRawFd for Fd { } impl Fd { - pub fn set_nonblocking(&self, nb: bool) -> nix::Result { + pub fn set_nonblocking(&mut self, nb: bool) -> nix::Result { use nix::fcntl; let mut flags = fcntl::OFlag::from_bits(fcntl::fcntl(self.0, fcntl::FcntlArg::F_GETFL)?).unwrap();