From a51984404c00beb6cecf4419842860fe41d23154 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 17 Aug 2024 10:44:36 +0200 Subject: [PATCH] Don't close direct descriptor using close(2) That doesn't work. --- src/fd.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/fd.rs b/src/fd.rs index 56e36a88..228a77a0 100644 --- a/src/fd.rs +++ b/src/fd.rs @@ -190,7 +190,7 @@ impl Drop for AsyncFd { }); if let Err(err) = result { log::warn!("error submitting close operation for a10::AsyncFd: {err}"); - if let Err(err) = syscall!(close(self.fd())) { + if let Err(err) = D::close(self.fd()) { log::warn!("error closing a10::AsyncFd: {err}"); } } @@ -202,6 +202,9 @@ impl Drop for AsyncFd { pub trait Descriptor: private::Descriptor {} pub(crate) mod private { + use std::os::fd::RawFd; + use std::io; + use crate::op::Submission; pub(crate) trait Descriptor { @@ -220,6 +223,8 @@ pub(crate) mod private { /// Debug representation of the descriptor. fn fmt_dbg() -> &'static str; + + fn close(fd: RawFd) -> io::Result<()>; } } @@ -249,6 +254,11 @@ impl private::Descriptor for File { fn fmt_dbg() -> &'static str { "file descriptor" } + + fn close(fd: RawFd) -> io::Result<()> { + syscall!(close(fd))?; + Ok(()) + } } /// Direct descriptors are io_uring private file descriptors. @@ -281,6 +291,12 @@ impl private::Descriptor for Direct { fn fmt_dbg() -> &'static str { "direct descriptor" } + + fn close(fd: RawFd) -> io::Result<()> { + // TODO: don't leak the the fd. + log::warn!("leaking direct descriptor {fd}"); + Ok(()) + } } // ToFd.