summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeorge Melikov <[email protected]>2017-01-23 21:07:09 +0300
committerBrian Behlendorf <[email protected]>2017-01-23 10:07:09 -0800
commit3cbe6b29f5832ef350b0ec4ecbba882e5210b56b (patch)
tree578275c3b7fbcab8af77d729f6e14718a0f2a48b /lib
parente67a7ffb5d1f4255a89d7511ea3554c7c7488e5a (diff)
OpenZFS 7233 - dir_is_empty should open directory with CLOEXEC
Authored by: Alex Reece <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Reviewed by: Paul Dagnelie <[email protected]> Approved by: Richard Lowe <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Ported-by: George Melikov [email protected] OpenZFS-issue: https://www.illumos.org/issues/7233 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/d420209 Closes #5623
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_mount.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c
index a2bb471b3..5fc96f1ab 100644
--- a/lib/libzfs/libzfs_mount.c
+++ b/lib/libzfs/libzfs_mount.c
@@ -22,7 +22,7 @@
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2014, 2015 by Delphix. All rights reserved.
*/
/*
@@ -64,6 +64,7 @@
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
+#include <fcntl.h>
#include <libgen.h>
#include <libintl.h>
#include <stdio.h>
@@ -179,9 +180,16 @@ dir_is_empty(const char *dirname)
{
DIR *dirp;
struct dirent64 *dp;
+ int dirfd;
- if ((dirp = opendir(dirname)) == NULL)
+ if ((dirfd = openat(AT_FDCWD, dirname,
+ O_RDONLY | O_NDELAY | O_LARGEFILE | O_CLOEXEC, 0)) < 0) {
return (B_TRUE);
+ }
+
+ if ((dirp = fdopendir(dirfd)) == NULL) {
+ return (B_TRUE);
+ }
while ((dp = readdir64(dirp)) != NULL) {