summaryrefslogtreecommitdiff
path: root/src/dir.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-13 03:37:47 +0000
committerGitHub <noreply@github.com>2021-02-13 03:37:47 +0000
commit0bfa49a2968ebbc76cbb192277f7435e18841309 (patch)
tree4a44e47c555d7c376d685b76e7a8c7561e4c56d7 /src/dir.rs
parent3b8180c430fe838e4fd71b83e5f92db6386e5c57 (diff)
parentc9cb83a5f6a4ec315b187afcf899d5758647dd0f (diff)
downloadnix-0bfa49a2968ebbc76cbb192277f7435e18841309.zip
Merge #1382
1382: Don't implement Clone on Dir, SignalFd, and PtyMaster r=asomers a=asomers Since they close their file descriptors on Drop, it's almost impossible to use Clone without creating a double-close situation. Also, check for EBADF in SignalFd::drop and Dir::drop. Co-authored-by: Alan Somers <asomers@gmail.com>
Diffstat (limited to 'src/dir.rs')
-rw-r--r--src/dir.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/dir.rs b/src/dir.rs
index 1d48f18c..1898950f 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -25,7 +25,7 @@ use libc::{dirent, readdir_r};
/// * returns entries for `.` (current directory) and `..` (parent directory).
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
/// does).
-#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Dir(
ptr::NonNull<libc::DIR>
);
@@ -85,7 +85,10 @@ impl AsRawFd for Dir {
impl Drop for Dir {
fn drop(&mut self) {
- unsafe { libc::closedir(self.0.as_ptr()) };
+ let e = Errno::result(unsafe { libc::closedir(self.0.as_ptr()) });
+ if !std::thread::panicking() && e == Err(Error::Sys(Errno::EBADF)) {
+ panic!("Closing an invalid file descriptor!");
+ };
}
}