about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-04-18 14:56:51 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-04-18 14:56:51 +0200
commitcef9b65376a044309f74b77860ccf3c48a4ae315 (patch)
treec934a9b57903468b9a2754c1cf8f99f2a94c9269 /sysdeps
parentb48061e1a534a2421c65e4258418d41a5335ba32 (diff)
downloadglibc-cef9b65376a044309f74b77860ccf3c48a4ae315.tar.gz
glibc-cef9b65376a044309f74b77860ccf3c48a4ae315.tar.xz
glibc-cef9b65376a044309f74b77860ccf3c48a4ae315.zip
Assume that O_CLOEXEC is always defined and works
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/mach/hurd/kernel-features.h1
-rw-r--r--sysdeps/nacl/kernel-features.h2
-rw-r--r--sysdeps/posix/getcwd.c8
-rw-r--r--sysdeps/posix/opendir.c47
-rw-r--r--sysdeps/posix/shm_open.c28
-rw-r--r--sysdeps/unix/sysv/linux/kernel-features.h4
6 files changed, 11 insertions, 79 deletions
diff --git a/sysdeps/mach/hurd/kernel-features.h b/sysdeps/mach/hurd/kernel-features.h
index 60c5bca01b..20cb3ba7bf 100644
--- a/sysdeps/mach/hurd/kernel-features.h
+++ b/sysdeps/mach/hurd/kernel-features.h
@@ -20,5 +20,4 @@
    Almost none of these are used outside of sysdeps/unix/sysv/linux code.
    But those referring to POSIX-level features like O_* flags can be.  */
 
-#define __ASSUME_O_CLOEXEC	1
 #define __ASSUME_ACCEPT4	1
diff --git a/sysdeps/nacl/kernel-features.h b/sysdeps/nacl/kernel-features.h
index 4a5808b56c..32834fd792 100644
--- a/sysdeps/nacl/kernel-features.h
+++ b/sysdeps/nacl/kernel-features.h
@@ -20,8 +20,6 @@
    Almost none of these are used outside of sysdeps/unix/sysv/linux code.
    But those referring to POSIX-level features like O_* flags can be.  */
 
-#define __ASSUME_O_CLOEXEC	1
-
 /*
 #define __ASSUME_ACCEPT4	1
 */
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index 0246e91d7c..eb1706aa5c 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -281,13 +281,7 @@ __getcwd (char *buf, size_t size)
   while (!(thisdev == rootdev && thisino == rootino))
     {
       if (__have_atfcts >= 0)
-	{
-	  int mode = O_RDONLY;
-#ifdef O_CLOEXEC
-	  mode |= O_CLOEXEC;
-#endif
-	  fd = openat64_not_cancel_3 (fd, "..", mode);
-	}
+	  fd = openat64_not_cancel_3 (fd, "..", O_RDONLY | O_CLOEXEC);
       else
 	fd = -1;
       if (fd >= 0)
diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c
index 75d833a908..909aa61884 100644
--- a/sysdeps/posix/opendir.c
+++ b/sysdeps/posix/opendir.c
@@ -81,6 +81,9 @@ tryopen_o_directory (void)
 # define EXTRA_FLAGS 0
 #endif
 
+enum {
+  opendir_oflags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE|O_CLOEXEC
+};
 
 static bool
 invalid_name (const char *name)
@@ -110,18 +113,6 @@ need_isdir_precheck (void)
   return true;
 }
 
-
-static int
-opendir_oflags (void)
-{
-  int flags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE;
-#ifdef O_CLOEXEC
-  flags |= O_CLOEXEC;
-#endif
-  return flags;
-}
-
-
 static DIR *
 opendir_tail (int fd)
 {
@@ -170,7 +161,7 @@ __opendirat (int dfd, const char *name)
 	}
     }
 
-  return opendir_tail (openat_not_cancel_3 (dfd, name, opendir_oflags ()));
+  return opendir_tail (openat_not_cancel_3 (dfd, name, opendir_oflags));
 }
 #endif
 
@@ -197,39 +188,19 @@ __opendir (const char *name)
 	}
     }
 
-  return opendir_tail (open_not_cancel_2 (name, opendir_oflags ()));
+  return opendir_tail (open_not_cancel_2 (name, opendir_oflags));
 }
 weak_alias (__opendir, opendir)
 
-
-#ifdef __ASSUME_O_CLOEXEC
-# define check_have_o_cloexec(fd) 1
-#else
-static int
-check_have_o_cloexec (int fd)
-{
-  if (__have_o_cloexec == 0)
-    __have_o_cloexec = (__fcntl (fd, F_GETFD, 0) & FD_CLOEXEC) == 0 ? -1 : 1;
-  return __have_o_cloexec > 0;
-}
-#endif
-
-
 DIR *
 internal_function
 __alloc_dir (int fd, bool close_fd, int flags, const struct stat64 *statp)
 {
-  /* We always have to set the close-on-exit flag if the user provided
-     the file descriptor.  Otherwise only if we have no working
-     O_CLOEXEC support.  */
-#ifdef O_CLOEXEC
-  if ((! close_fd && (flags & O_CLOEXEC) == 0)
-      || ! check_have_o_cloexec (fd))
-#endif
-    {
-      if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
+  /* We have to set the close-on-exit flag if the user provided the
+     file descriptor.  */
+  if (!close_fd
+      && __builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
 	goto lose;
-    }
 
   const size_t default_allocation = (4 * BUFSIZ < sizeof (struct dirent64)
 				     ? sizeof (struct dirent64) : 4 * BUFSIZ);
diff --git a/sysdeps/posix/shm_open.c b/sysdeps/posix/shm_open.c
index 56a9965263..64315de8f8 100644
--- a/sysdeps/posix/shm_open.c
+++ b/sysdeps/posix/shm_open.c
@@ -34,10 +34,7 @@ shm_open (const char *name, int oflag, mode_t mode)
 {
   SHM_GET_NAME (EINVAL, -1, "");
 
-  oflag |= O_NOFOLLOW;
-# ifdef O_CLOEXEC
-  oflag |= O_CLOEXEC;
-# endif
+  oflag |= O_NOFOLLOW | O_CLOEXEC;
 
   /* Disable asynchronous cancellation.  */
   int state;
@@ -50,29 +47,6 @@ shm_open (const char *name, int oflag, mode_t mode)
        object names and the standard does not mention EISDIR.  */
     __set_errno (EINVAL);
 
-# ifndef O_CLOEXEC
-  if (fd != -1)
-    {
-      /* We got a descriptor.  Now set the FD_CLOEXEC bit.  */
-      int flags = fcntl (fd, F_GETFD, 0);
-
-      if (__glibc_likely (flags != -1))
-	{
-	  flags |= FD_CLOEXEC;
-	  flags = fcntl (fd, F_SETFD, flags);
-	}
-
-      if (flags == -1)
-	{
-	  /* Something went wrong.  We cannot return the descriptor.  */
-	  int save_errno = errno;
-	  close (fd);
-	  fd = -1;
-	  __set_errno (save_errno);
-	}
-    }
-# endif
-
   pthread_setcancelstate (state, NULL);
 
   return fd;
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index e0eb4e2f84..fd936c5366 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -68,10 +68,6 @@
 #define __ASSUME_PRIVATE_FUTEX	1
 
 /* Support for various CLOEXEC and NONBLOCK flags was added in
-   2.6.23.  */
-#define __ASSUME_O_CLOEXEC	1
-
-/* Support for various CLOEXEC and NONBLOCK flags was added in
    2.6.27.  */
 #define __ASSUME_IN_NONBLOCK	1