* lib/opendir-safer.c: Include fcntl.h instead of unistd-safer.h.
(opendir_safer): Use F_DUPFD_CLOEXEC.
* modules/dirent-safer (Depends-on): Add fcntl. Remove unistd-safer.
* tests/test-dirent-safer.c: Do not include unistd-safer.h,
as it is no longer a prerequisite. Use F_DUPFD_CLOEXEC
instead of dup_safer.
2017-08-12 Paul Eggert <eggert@cs.ucla.edu>
+ dirent-safer: fix cloexec race
+ * lib/opendir-safer.c: Include fcntl.h instead of unistd-safer.h.
+ (opendir_safer): Use F_DUPFD_CLOEXEC.
+ * modules/dirent-safer (Depends-on): Add fcntl. Remove unistd-safer.
+ * tests/test-dirent-safer.c: Do not include unistd-safer.h,
+ as it is no longer a prerequisite. Use F_DUPFD_CLOEXEC
+ instead of dup_safer.
+
fts: fix cloexec races
* lib/fts.c [!_LIBC]: Do not include dirent--.h, unistd--.h, cloexec.h.
(opendirat, diropen): Use O_CLOEXEC instead of set_cloexec_flag.
#include "dirent-safer.h"
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
-#include "unistd-safer.h"
/* Like opendir, but do not clobber stdin, stdout, or stderr. */
DIR *newdp;
int e;
#if HAVE_FDOPENDIR || GNULIB_FDOPENDIR
- int f = dup_safer (fd);
+ int f = fcntl (fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
if (f < 0)
{
e = errno;
dirent
closedir
dirfd
+fcntl
opendir
-unistd-safer
configure.ac:
gl_DIRENT_SAFER
#include <stdio.h>
#include <unistd.h>
-#include "unistd-safer.h"
-
/* This test intentionally closes stderr. So, we arrange to have fd 10
(outside the range of interesting fd's during the test) set up to
duplicate the original stderr. */
#if HAVE_FDOPENDIR || GNULIB_TEST_FDOPENDIR
{
- int fd = dup_safer (dfd);
+ int fd = fcntl (dfd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
ASSERT (STDERR_FILENO < fd);
dp = fdopendir (fd);
ASSERT (dp);