From 1c02eebc71a0ede4e75fea516920697850bbe030 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Tue, 4 Jan 2022 03:51:32 -0600 Subject: Implement unmount --- src/util.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/util.rs') diff --git a/src/util.rs b/src/util.rs index c21442f..5da19c8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -29,6 +29,12 @@ pub struct OutputChain<'a> { pub struct OutputChainIter<'a>(Option<&'a OutputChain<'a>>); +impl DumbFd { + pub fn take(&mut self) -> DumbFd { + DumbFd(std::mem::replace(&mut self.0, -1)) + } +} + impl IntoRawFd for DumbFd { fn into_raw_fd(self) -> RawFd { let fd = self.0; @@ -39,7 +45,9 @@ impl IntoRawFd for DumbFd { impl Drop for DumbFd { fn drop(&mut self) { - let _ = close(self.0); + if !self.0.is_negative() { + let _ = close(self.0); + } } } -- cgit v1.2.3