From d420209d9c807f782c1d31f5683be74798142198 Mon Sep 17 00:00:00 2001 From: Alex Reece Date: Thu, 18 Aug 2016 15:49:50 -0700 Subject: [PATCH] 7233 dir_is_empty should open directory with CLOEXEC Reviewed by: Matthew Ahrens Reviewed by: Paul Dagnelie Approved by: Richard Lowe --- usr/src/lib/libzfs/common/libzfs_mount.c | 12 ++++++++++-- 1 file 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 */ @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -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) { -- 2.11.4.GIT