blocking fixup, and actually recvmsg on recvmsg

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-10-31 09:18:08 +01:00
parent 8dd2698556
commit 1282264afc
4 changed files with 7 additions and 5 deletions

View File

@ -11,6 +11,7 @@ use std::panic::UnwindSafe;
use crate::io::pipe::{self, Pipe}; use crate::io::pipe::{self, Pipe};
use crate::syscall::SyscallStatus; use crate::syscall::SyscallStatus;
use crate::tools::Fd;
pub async fn forking_syscall<F>(func: F) -> io::Result<SyscallStatus> pub async fn forking_syscall<F>(func: F) -> io::Result<SyscallStatus>
where where
@ -54,9 +55,10 @@ impl Fork {
let pid = c_try!(unsafe { libc::fork() }); let pid = c_try!(unsafe { libc::fork() });
if pid == 0 { if pid == 0 {
drop(pipe_r); 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 || { 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() { let out = match func() {
Ok(SyscallStatus::Ok(val)) => Data { Ok(SyscallStatus::Ok(val)) => Data {
val, val,

View File

@ -171,7 +171,7 @@ impl IntoRawFd for PolledFd {
} }
impl PolledFd { impl PolledFd {
pub fn new(fd: Fd) -> io::Result<Self> { pub fn new(mut fd: Fd) -> io::Result<Self> {
fd.set_nonblocking(true).map_err(io_err_other)?; fd.set_nonblocking(true).map_err(io_err_other)?;
Self::new_with_reactor(fd, self::default_reactor()) Self::new_with_reactor(fd, self::default_reactor())
} }

View File

@ -116,7 +116,7 @@ impl SeqPacketSocket {
let fd = self.fd.as_raw_fd(); let fd = self.fd.as_raw_fd();
self.fd.wrap_read(cx, || { 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) .map(|rc| rc as usize)
}) })
} }

View File

@ -20,7 +20,7 @@ impl FromRawFd for Fd {
} }
impl Fd { impl Fd {
pub fn set_nonblocking(&self, nb: bool) -> nix::Result<libc::c_int> { pub fn set_nonblocking(&mut self, nb: bool) -> nix::Result<libc::c_int> {
use nix::fcntl; use nix::fcntl;
let mut flags = let mut flags =
fcntl::OFlag::from_bits(fcntl::fcntl(self.0, fcntl::FcntlArg::F_GETFL)?).unwrap(); fcntl::OFlag::from_bits(fcntl::fcntl(self.0, fcntl::FcntlArg::F_GETFL)?).unwrap();