summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Reece <alex@delphix.com>2016-08-18 15:49:50 -0700
committerMatthew Ahrens <mahrens@delphix.com>2016-08-18 16:48:06 -0700
commitd420209d9c807f782c1d31f5683be74798142198 (patch)
treeaa1c0b5d282414e58a4077898ad2021233a13f66
parent1033d75249caf2f4829363492fba5ce7044cd11f (diff)
downloadillumos-joyent-d420209d9c807f782c1d31f5683be74798142198.tar.gz
7233 dir_is_empty should open directory with CLOEXEC
Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Paul Dagnelie <pcd@delphix.com> Approved by: Richard Lowe <richlowe@richlowe.net>
-rw-r--r--usr/src/lib/libzfs/common/libzfs_mount.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_mount.c b/usr/src/lib/libzfs/common/libzfs_mount.c
index f74860ba67..bc4dbf9c3d 100644
--- a/usr/src/lib/libzfs/common/libzfs_mount.c
+++ b/usr/src/lib/libzfs/common/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.
* Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
*/
@@ -65,6 +65,7 @@
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
+#include <fcntl.h>
#include <libgen.h>
#include <libintl.h>
#include <stdio.h>
@@ -180,9 +181,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) {