From eb3af1b4ab071e7e3a1f01a3f62390f976592e06 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 21 Feb 2016 16:09:23 -0500 Subject: bftw: Use O_CLOEXEC. --- bftw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bftw.c b/bftw.c index 7ad36a6..8c8d8b4 100644 --- a/bftw.c +++ b/bftw.c @@ -399,7 +399,7 @@ static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *e asdf = asdf->parent; } while (asdf != base); - int flags = O_DIRECTORY; + int flags = O_RDONLY | O_DIRECTORY | O_CLOEXEC; int fd = openat(at_fd, at_path, flags); if (fd < 0 && dircache_should_retry(cache, base)) { @@ -417,10 +417,10 @@ static DIR *dircache_entry_open(struct dircache *cache, struct dircache_entry *e // footprint significantly, while keeping the fd around for future // openat() calls. - fd = dup(entry->fd); + fd = fcntl(entry->fd, F_DUPFD_CLOEXEC, 0); if (fd < 0 && dircache_should_retry(cache, entry)) { - fd = dup(entry->fd); + fd = fcntl(entry->fd, F_DUPFD_CLOEXEC, 0); } if (fd < 0) { return NULL; -- cgit v1.2.3