From 3cbe6b29f5832ef350b0ec4ecbba882e5210b56b Mon Sep 17 00:00:00 2001 From: George Melikov Date: Mon, 23 Jan 2017 21:07:09 +0300 Subject: [PATCH] OpenZFS 7233 - dir_is_empty should open directory with CLOEXEC Authored by: Alex Reece Reviewed by: Matthew Ahrens Reviewed by: Paul Dagnelie Approved by: Richard Lowe Reviewed-by: Brian Behlendorf Ported-by: George Melikov mail@gmelikov.ru OpenZFS-issue: https://www.illumos.org/issues/7233 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/d420209 Closes #5623 --- lib/libzfs/libzfs_mount.c | 12 ++++++++++-- 1 file 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 #include #include +#include #include #include #include @@ -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) {