This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch fw/accept4 created. glibc-2.25-224-g02191c9


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, fw/accept4 has been created
        at  02191c903188162a48f57a4644dcd74809011151 (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=02191c903188162a48f57a4644dcd74809011151

commit 02191c903188162a48f57a4644dcd74809011151
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Apr 14 10:30:01 2017 +0200

    Assume that accept4 is always available and works
    
    Simplify the Linux accept4 implementation based on the assumption
    that it is available in some way.  __ASSUME_ACCEPT4_SOCKETCALL was
    previously unused, so remove it.  Its functionality is implied
    by the complex #if condition in accept4.c.

diff --git a/ChangeLog b/ChangeLog
index e8e5b98..1085153 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2017-04-14  Florian Weimer  <fweimer@redhat.com>
+
+	* nscd/connections.c (have_accept4): Removed definition.
+	(nscd_run_worker, main_loop_poll, main_loop_epolll): Assume that
+	accept4 works.
+	* manual/install.texi (Linux): Require at least kernel 3.2.18 for
+	ia64 because that was the first version with accept4 support.
+	* support/Makefile (libsupport-routines): Add xaccept4.
+	* support/xsocket.h (xaccept4): Declare.
+	* support/xaccept4.c: New file.
+	* socket/tst-accept4.c: New file.
+	* socket/Makefile (tests): Add tst-accept4.
+	* sysdeps/mach/hurd/kernel-features.h (__ASSUME_ACCEPT4): Remove
+	definition.
+	* sysdeps/nacl/kernel-features.h (__ASSUME_ACCEPT4): Remove
+	comment.
+	* sysdeps/unix/sysv/linux/accept4.c: Assume that an accept4
+	implementation is available.
+	(accept4): Use the system call if available, otherwise use the
+	socket call.
+	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
+	(__ASSUME_ACCEPT4_SYSCALL, __ASSUME_ACCEPT4): Do not undefine.
+	accept4 is unconditionally available in later 3.2 stable kernels.
+	(__ASSUME_ACCEPT4_SYSCALL): Define.
+	* sysdeps/unix/sysv/linux/kernel-features.h
+	(__ASSUME_ACCEPT4_SOCKETCALL, __ASSUME_ACCEPT4): Remove
+	definitions.
+	* sysdeps/unix/sysv/linux/i386/kernel-features.h
+	(__ASSUME_ACCEPT4_SYSCALL): Define for Linux 4.3 or later.
+
 2017-04-13  Florian Weimer  <fweimer@redhat.com>
 
 	* elf/dl-misc.c (_dl_sysdep_read_whole_file): Assume that
diff --git a/INSTALL b/INSTALL
index 60f714e..51989b2 100644
--- a/INSTALL
+++ b/INSTALL
@@ -500,21 +500,21 @@ Specific advice for GNU/Linux systems
 =====================================
 
 If you are installing the GNU C Library on GNU/Linux systems, you need
-to have the header files from a 3.2 or newer kernel around for
-reference.  These headers must be installed using 'make
-headers_install'; the headers present in the kernel source directory are
-not suitable for direct use by the GNU C Library.  You do not need to
-use that kernel, just have its headers installed where the GNU C Library
-can access them, referred to here as INSTALL-DIRECTORY.  The easiest way
-to do this is to unpack it in a directory such as
-'/usr/src/linux-VERSION'.  In that directory, run 'make headers_install
-INSTALL_HDR_PATH=INSTALL-DIRECTORY'.  Finally, configure the GNU C
-Library with the option '--with-headers=INSTALL-DIRECTORY/include'.  Use
-the most recent kernel you can get your hands on.  (If you are
-cross-compiling the GNU C Library, you need to specify
-'ARCH=ARCHITECTURE' in the 'make headers_install' command, where
-ARCHITECTURE is the architecture name used by the Linux kernel, such as
-'x86' or 'powerpc'.)
+to have the header files from a 3.2 or newer kernel (a 3.2.18 or newer
+kernel for the ia64 architecture) around for reference.  These headers
+must be installed using 'make headers_install'; the headers present in
+the kernel source directory are not suitable for direct use by the GNU C
+Library.  You do not need to use that kernel, just have its headers
+installed where the GNU C Library can access them, referred to here as
+INSTALL-DIRECTORY.  The easiest way to do this is to unpack it in a
+directory such as '/usr/src/linux-VERSION'.  In that directory, run
+'make headers_install INSTALL_HDR_PATH=INSTALL-DIRECTORY'.  Finally,
+configure the GNU C Library with the option
+'--with-headers=INSTALL-DIRECTORY/include'.  Use the most recent kernel
+you can get your hands on.  (If you are cross-compiling the GNU C
+Library, you need to specify 'ARCH=ARCHITECTURE' in the 'make
+headers_install' command, where ARCHITECTURE is the architecture name
+used by the Linux kernel, such as 'x86' or 'powerpc'.)
 
    After installing the GNU C Library, you may need to remove or rename
 directories such as '/usr/include/linux' and '/usr/include/asm', and
diff --git a/manual/install.texi b/manual/install.texi
index 99397c2..43eafa3 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -564,22 +564,24 @@ patches, although we try to avoid this.
 @appendixsec Specific advice for @gnulinuxsystems{}
 @cindex kernel header files
 
-If you are installing @theglibc{} on @gnulinuxsystems{}, you need to have
-the header files from a 3.2 or newer kernel around for reference.
-These headers must be installed using @samp{make headers_install}; the
-headers present in the kernel source directory are not suitable for
-direct use by @theglibc{}.  You do not need to use that kernel, just have
-its headers installed where @theglibc{} can access them, referred to here as
-@var{install-directory}.  The easiest way to do this is to unpack it
-in a directory such as @file{/usr/src/linux-@var{version}}.  In that
+If you are installing @theglibc{} on @gnulinuxsystems{}, you need to
+have the header files from a 3.2 or newer kernel (a 3.2.18 or newer
+kernel for the ia64 architecture) around for reference.  These headers
+must be installed using @samp{make headers_install}; the headers present
+in the kernel source directory are not suitable for direct use by
+@theglibc{}.  You do not need to use that kernel, just have its headers
+installed where @theglibc{} can access them, referred to here as
+@var{install-directory}.  The easiest way to do this is to unpack it in
+a directory such as @file{/usr/src/linux-@var{version}}.  In that
 directory, run @samp{make headers_install
-INSTALL_HDR_PATH=@var{install-directory}}.  Finally, configure @theglibc{}
-with the option @samp{--with-headers=@var{install-directory}/include}.
-Use the most recent kernel you can get your hands on.  (If you are
-cross-compiling @theglibc{}, you need to specify
-@samp{ARCH=@var{architecture}} in the @samp{make headers_install}
-command, where @var{architecture} is the architecture name used by the
-Linux kernel, such as @samp{x86} or @samp{powerpc}.)
+INSTALL_HDR_PATH=@var{install-directory}}.  Finally, configure
+@theglibc{} with the option
+@samp{--with-headers=@var{install-directory}/include}.  Use the most
+recent kernel you can get your hands on.  (If you are cross-compiling
+@theglibc{}, you need to specify @samp{ARCH=@var{architecture}} in the
+@samp{make headers_install} command, where @var{architecture} is the
+architecture name used by the Linux kernel, such as @samp{x86} or
+@samp{powerpc}.)
 
 After installing @theglibc{}, you may need to remove or rename
 directories such as @file{/usr/include/linux} and
diff --git a/nscd/connections.c b/nscd/connections.c
index a5ca57a..cc1ed72 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -257,10 +257,6 @@ int inotify_fd = -1;
 static int nl_status_fd = -1;
 #endif
 
-#ifndef __ASSUME_ACCEPT4
-static int have_accept4;
-#endif
-
 /* Number of times clients had to wait.  */
 unsigned long int client_queued;
 
@@ -1650,16 +1646,6 @@ nscd_run_worker (void *p)
       /* We are done with the list.  */
       pthread_mutex_unlock (&readylist_lock);
 
-#ifndef __ASSUME_ACCEPT4
-      if (have_accept4 < 0)
-	{
-	  /* We do not want to block on a short read or so.  */
-	  int fl = fcntl (fd, F_GETFL);
-	  if (fl == -1 || fcntl (fd, F_SETFL, fl | O_NONBLOCK) == -1)
-	    goto close_and_out;
-	}
-#endif
-
       /* Now read the request.  */
       request_header req;
       if (__builtin_expect (TEMP_FAILURE_RETRY (read (fd, &req, sizeof (req)))
@@ -2099,24 +2085,8 @@ main_loop_poll (void)
 	  if (conns[0].revents != 0)
 	    {
 	      /* We have a new incoming connection.  Accept the connection.  */
-	      int fd;
-
-#ifndef __ASSUME_ACCEPT4
-	      fd = -1;
-	      if (have_accept4 >= 0)
-#endif
-		{
-		  fd = TEMP_FAILURE_RETRY (accept4 (sock, NULL, NULL,
+	      int fd = TEMP_FAILURE_RETRY (accept4 (sock, NULL, NULL,
 						    SOCK_NONBLOCK));
-#ifndef __ASSUME_ACCEPT4
-		  if (have_accept4 == 0)
-		    have_accept4 = fd != -1 || errno != ENOSYS ? 1 : -1;
-#endif
-		}
-#ifndef __ASSUME_ACCEPT4
-	      if (have_accept4 < 0)
-		fd = TEMP_FAILURE_RETRY (accept (sock, NULL, NULL));
-#endif
 
 	      /* Use the descriptor if we have not reached the limit.  */
 	      if (fd >= 0)
@@ -2284,24 +2254,8 @@ main_loop_epoll (int efd)
 	if (revs[cnt].data.fd == sock)
 	  {
 	    /* A new connection.  */
-	    int fd;
-
-# ifndef __ASSUME_ACCEPT4
-	    fd = -1;
-	    if (have_accept4 >= 0)
-# endif
-	      {
-		fd = TEMP_FAILURE_RETRY (accept4 (sock, NULL, NULL,
+	    int fd = TEMP_FAILURE_RETRY (accept4 (sock, NULL, NULL,
 						  SOCK_NONBLOCK));
-# ifndef __ASSUME_ACCEPT4
-		if (have_accept4 == 0)
-		  have_accept4 = fd != -1 || errno != ENOSYS ? 1 : -1;
-# endif
-	      }
-# ifndef __ASSUME_ACCEPT4
-	    if (have_accept4 < 0)
-	      fd = TEMP_FAILURE_RETRY (accept (sock, NULL, NULL));
-# endif
 
 	    /* Use the descriptor if we have not reached the limit.  */
 	    if (fd >= 0)
diff --git a/socket/Makefile b/socket/Makefile
index 25d4f68..1e2555d 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -31,6 +31,8 @@ routines := accept bind connect getpeername getsockname getsockopt	\
 	    setsockopt shutdown socket socketpair isfdtype opensock	\
 	    sockatmark accept4 recvmmsg sendmmsg
 
+tests := tst-accept4
+
 aux	 := sa_len
 
 include ../Rules
diff --git a/socket/tst-accept4.c b/socket/tst-accept4.c
new file mode 100644
index 0000000..c096e8c
--- /dev/null
+++ b/socket/tst-accept4.c
@@ -0,0 +1,129 @@
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <support/check.h>
+#include <support/xsocket.h>
+#include <support/xunistd.h>
+#include <sys/socket.h>
+
+static bool
+is_nonblocking (int fd)
+{
+  int status = fcntl (fd, F_GETFL);
+  if (status < 0)
+    FAIL_EXIT1 ("fcntl (F_GETFL): %m");
+  return status & O_NONBLOCK;
+}
+
+static bool
+is_cloexec (int fd)
+{
+  int status = fcntl (fd, F_GETFD);
+  if (status < 0)
+    FAIL_EXIT1 ("fcntl (F_GETFD): %m");
+  return status & FD_CLOEXEC;
+}
+
+struct client
+{
+  int socket;
+  struct sockaddr_in address;
+};
+
+/* Perform a non-blocking connect to *SERVER_ADDRESS.  */
+static struct client
+client_connect (const struct sockaddr_in *server_address)
+{
+  struct client result;
+  result.socket = xsocket (AF_INET,
+                           SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
+  TEST_VERIFY (is_nonblocking (result.socket));
+  TEST_VERIFY (is_cloexec (result.socket));
+  int ret = connect (result.socket, (const struct sockaddr *) server_address,
+                     sizeof (*server_address));
+  if (ret < 0 && errno != EINPROGRESS)
+    FAIL_EXIT1 ("client connect: %m");
+  socklen_t sa_len = sizeof (result.address);
+  xgetsockname (result.socket, (struct sockaddr *) &result.address,
+                &sa_len);
+  TEST_VERIFY (sa_len == sizeof (result.address));
+  return result;
+}
+
+static void
+check_same_address (const struct sockaddr_in *left,
+                    const struct sockaddr_in *right)
+{
+  TEST_VERIFY (left->sin_family == AF_INET);
+  TEST_VERIFY (right->sin_family == AF_INET);
+  TEST_VERIFY (left->sin_addr.s_addr == right->sin_addr.s_addr);
+  TEST_VERIFY (left->sin_port == right->sin_port);
+}
+
+static int
+do_test (void)
+{
+  /* Create server socket.  */
+  int server_socket = xsocket (AF_INET, SOCK_STREAM, 0);
+  TEST_VERIFY (!is_nonblocking (server_socket));
+  TEST_VERIFY (!is_cloexec (server_socket));
+  struct sockaddr_in server_address =
+    {
+      .sin_family = AF_INET,
+      .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) },
+    };
+  xbind (server_socket,
+         (struct sockaddr *) &server_address, sizeof (server_address));
+  {
+    socklen_t sa_len = sizeof (server_address);
+    xgetsockname (server_socket, (struct sockaddr *) &server_address,
+                  &sa_len);
+    TEST_VERIFY (sa_len == sizeof (server_address));
+  }
+  xlisten (server_socket, 5);
+
+  for (int do_nonblock = 0; do_nonblock < 2; ++do_nonblock)
+    for (int do_cloexec = 0; do_cloexec < 2; ++do_cloexec)
+      {
+        int sockflags = 0;
+        if (do_nonblock)
+          sockflags |= SOCK_NONBLOCK;
+        if (do_cloexec)
+          sockflags |= SOCK_CLOEXEC;
+
+        struct client client = client_connect (&server_address);
+        struct sockaddr_in client_address;
+        socklen_t sa_len = sizeof (client_address);
+        int client_socket = xaccept4 (server_socket,
+                                      (struct sockaddr *) &client_address,
+                                      &sa_len, sockflags);
+        TEST_VERIFY (sa_len == sizeof (client_address));
+        TEST_VERIFY (is_nonblocking (client_socket) == do_nonblock);
+        TEST_VERIFY (is_cloexec (client_socket) == do_cloexec);
+        check_same_address (&client.address, &client_address);
+        xclose (client_socket);
+        xclose (client.socket);
+      }
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/support/Makefile b/support/Makefile
index 1f33fa0..38dbd83 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -50,6 +50,7 @@ libsupport-routines = \
   temp_file \
   write_message \
   xaccept \
+  xaccept4 \
   xasprintf \
   xbind \
   xcalloc \
diff --git a/sysdeps/mach/hurd/kernel-features.h b/support/xaccept4.c
similarity index 64%
copy from sysdeps/mach/hurd/kernel-features.h
copy to support/xaccept4.c
index 20cb3ba..b676b58 100644
--- a/sysdeps/mach/hurd/kernel-features.h
+++ b/support/xaccept4.c
@@ -1,5 +1,5 @@
-/* Set flags signalling availability of certain operating system features.
-   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+/* accept with error checking.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,8 +16,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* This file can define __ASSUME_* macros checked by certain source files.
-   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.  */
+#include <support/xsocket.h>
 
-#define __ASSUME_ACCEPT4	1
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+
+int
+xaccept4 (int fd, struct sockaddr *sa, socklen_t *salen, int flags)
+{
+  int clientfd = accept4 (fd, sa, salen, flags);
+  if (clientfd < 0)
+    FAIL_EXIT1 ("accept4 (%d, 0x%x): %m", fd, flags);
+  return clientfd;
+}
diff --git a/support/xsocket.h b/support/xsocket.h
index 0dbf13a..d672494 100644
--- a/support/xsocket.h
+++ b/support/xsocket.h
@@ -30,6 +30,7 @@ void xconnect (int, const struct sockaddr *, socklen_t);
 void xbind (int, const struct sockaddr *, socklen_t);
 void xlisten (int, int);
 int xaccept (int, struct sockaddr *, socklen_t *);
+int xaccept4 (int, struct sockaddr *, socklen_t *, int);
 void xsendto (int, const void *, size_t, int,
               const struct sockaddr *, socklen_t);
 size_t xrecvfrom (int, void *, size_t, int, struct sockaddr *, socklen_t *);
diff --git a/sysdeps/mach/hurd/kernel-features.h b/sysdeps/mach/hurd/kernel-features.h
index 20cb3ba..1966388 100644
--- a/sysdeps/mach/hurd/kernel-features.h
+++ b/sysdeps/mach/hurd/kernel-features.h
@@ -19,5 +19,3 @@
 /* This file can define __ASSUME_* macros checked by certain source files.
    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_ACCEPT4	1
diff --git a/sysdeps/nacl/kernel-features.h b/sysdeps/nacl/kernel-features.h
index 32834fd..ba315b6 100644
--- a/sysdeps/nacl/kernel-features.h
+++ b/sysdeps/nacl/kernel-features.h
@@ -19,7 +19,3 @@
 /* This file can define __ASSUME_* macros checked by certain source files.
    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_ACCEPT4	1
-*/
diff --git a/sysdeps/unix/sysv/linux/accept4.c b/sysdeps/unix/sysv/linux/accept4.c
index 53afd7a..0592f43 100644
--- a/sysdeps/unix/sysv/linux/accept4.c
+++ b/sysdeps/unix/sysv/linux/accept4.c
@@ -22,75 +22,20 @@
 
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
+#include <socketcall.h>
 #include <kernel-features.h>
 
+int
+accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
+{
 /* Do not use the accept4 syscall on socketcall architectures unless
    it was added at the same time as the socketcall support or can be
    assumed to be present.  */
 #if defined __ASSUME_SOCKETCALL \
     && !defined __ASSUME_ACCEPT4_SYSCALL_WITH_SOCKETCALL \
     && !defined __ASSUME_ACCEPT4_SYSCALL
-# undef __NR_accept4
-#endif
-
-#ifdef __NR_accept4
-int
-accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
-{
-  return SYSCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len, flags);
-}
-#elif defined __NR_socketcall
-# include <socketcall.h>
-# ifdef __ASSUME_ACCEPT4_SOCKETCALL
-int
-accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
-{
   return SOCKETCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len, flags);
-}
-# else
-static int have_accept4;
-
-int
-accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
-{
-  if (__glibc_likely (have_accept4 >= 0))
-    {
-      int ret = SOCKETCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len,
-				   flags);
-      /* The kernel returns -EINVAL for unknown socket operations.
-	 We need to convert that error to an ENOSYS error.  */
-      if (__builtin_expect (ret < 0, 0)
-	  && have_accept4 == 0
-	  && errno == EINVAL)
-	{
-	  /* Try another call, this time with the FLAGS parameter
-	     cleared and an invalid file descriptor.  This call will not
-	     cause any harm and it will return immediately.  */
-	  ret = SOCKETCALL_CANCEL (invalid, -1);
-	  if (errno == EINVAL)
-	    {
-	      have_accept4 = -1;
-	      __set_errno (ENOSYS);
-	    }
-	  else
-	    {
-	      have_accept4 = 1;
-	      __set_errno (EINVAL);
-	    }
-	  return -1;
-	}
-      return ret;
-    }
-  __set_errno (ENOSYS);
-  return -1;
-}
-# endif /* __ASSUME_ACCEPT4_SOCKETCALL  */
-#else /* __NR_socketcall   */
-int
-accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
-{
-  __set_errno (ENOSYS);
-  return -1;
-}
-stub_warning (accept4)
+#else
+  return SYSCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len, flags);
 #endif
+}
diff --git a/sysdeps/unix/sysv/linux/ia64/kernel-features.h b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
index ac9403e..cda0ad6 100644
--- a/sysdeps/unix/sysv/linux/ia64/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
@@ -22,13 +22,8 @@
 
 #include_next <kernel-features.h>
 
-/* Support for the accept4 syscall was added in 3.3.  */
-#if __LINUX_KERNEL_VERSION < 0x030300
-# undef __ASSUME_ACCEPT4_SYSCALL
-# undef __ASSUME_ACCEPT4
-#endif
-
 #define __ASSUME_RECV_SYSCALL   	1
 #define __ASSUME_SEND_SYSCALL		1
+#define __ASSUME_ACCEPT4_SYSCALL	1
 
 #endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index fd936c5..b981466 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -75,18 +75,11 @@
    architectures using a separate syscall rather than socketcall that
    syscall was only added later, and some architectures first had
    socketcall support then a separate syscall.  Define
-   __ASSUME_ACCEPT4_SOCKETCALL if glibc uses socketcall on this
-   architecture and accept4 is available through socketcall,
    __ASSUME_ACCEPT4_SYSCALL if it is available through a separate
-   syscall, __ASSUME_ACCEPT4_SYSCALL_WITH_SOCKETCALL if it became
+   syscall, and __ASSUME_ACCEPT4_SYSCALL_WITH_SOCKETCALL if it became
    available through a separate syscall at the same time as through
-   socketcall, and __ASSUME_ACCEPT4 if the accept4 function is known
-   to work.  */
-#ifdef __ASSUME_SOCKETCALL
-# define __ASSUME_ACCEPT4_SOCKETCALL	1
-#endif
+   socketcall.  */
 #define __ASSUME_ACCEPT4_SYSCALL	1
-#define __ASSUME_ACCEPT4	1
 
 /* Support for the FUTEX_CLOCK_REALTIME flag was added in 2.6.29.  */
 #define __ASSUME_FUTEX_CLOCK_REALTIME	1

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6417a03b98b851c7e5fea01ffd744d497971277e

commit 6417a03b98b851c7e5fea01ffd744d497971277e
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu Apr 13 21:52:16 2017 +0200

    Assume that O_CLOEXEC is always defined and works

diff --git a/ChangeLog b/ChangeLog
index b178f10..e8e5b98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,61 @@
 2017-04-13  Florian Weimer  <fweimer@redhat.com>
 
+	* elf/dl-misc.c (_dl_sysdep_read_whole_file): Assume that
+	O_CLOEXEC is defined.
+	* include/fcntl.h (__have_o_cloexec): Remove declaration.
+	* io/Makefile (aux): Remove.
+	* io/have_o_cloexec.c: Remove file.
+	* libio/fileops.c (_IO_new_file_fopen): Assume that O_CLOEXEC is
+	defined and works.
+	* libio/iopopen.c (_IO_new_proc_open): Assume that O_CLOEXEC is
+	defined.
+	* login/utmp_file.c (O_flags): Remove definition.
+	(setutent_file): Use O_CLOEXEC instead of O_flags.  Assume that
+	O_CLOEXEC works.
+	(pututline_file): Likewise.
+	* malloc/mtrace.c: Assume that O_CLOEXEC works.
+	* nis/nss_compat/compat-grp.c (__compat_have_cloexec): Remove
+	definition.
+	(internal_setgrent): Assume that O_CLOEXEC works.
+	* nis/nss_compat/compat-initgroups.c (__compat_have_cloexec):
+	Remove definition.
+	(internal_setgrent): Assume that O_CLOEXEC works.
+	* nis/nss_compat/compat-pwd.c (__compat_have_cloexec): Remove
+	definition.
+	(internal_setpwent): Assume that O_CLOEXEC works.
+	* nis/nss_compat/compat-spwd.c (__compat_have_cloexec): Remove
+	definition.
+	(internal_setspent): Assume that O_CLOEXEC works.
+	* nscd/connections.c (EXTRA_O_FLAGS): Remove definition.
+	(nscd_init): Use O_CLOEXEC instead of EXTRA_O_FLAGS.  Assume that
+	O_CLOEXEC is defined and works.
+	* nss/Makefile (libnss_files-routines): Remove
+	files-have_o_cloexec.
+	* nss/nss_db/db-open.c (internal_setent): Assume that O_CLOEXEC is
+	defined.
+	* nss/nss_files/files-XXX.c (internal_setent): Assume that
+	O_CLOEXEC is defined and works.
+	* nss/nss_files/files-alias.c (internal_setent): Likewise.
+	* nss/nss_files/files-have_o_cloexec.c: Remove.
+	* posix/wordexp.c (exec_comm_child, exec_comm): Assume that
+	O_CLOEXEC is defined.
+	* shadow/lckpwdf.c (__lckpwdf): Assume that O_CLOEXEC is defined
+	and works.
+	* sysdeps/mach/hurd/kernel-features.h (__ASSUME_O_CLOEXEC): Remove
+	definition.
+	* sysdeps/nacl/kernel-features.h (__ASSUME_O_CLOEXEC): Likewise.
+	* sysdeps/posix/getcwd.c (__getcwd): Assume that O_CLOEXEC works.
+	* sysdeps/posix/opendir.c (opendir_oflags): Turn into enum constant.
+	(__opendirat, __opendir): Adjust opendir_oflags call.
+	(check_have_o_cloexec): Remove.
+	(__alloc_dir): Assume that O_CLOEXEC is defined and works.
+	* sysdeps/posix/shm_open.c (shm_open): Assume that O_CLOEXEC is
+	defined.
+	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_O_CLOEXEC):
+	Remove definition.
+
+2017-04-13  Florian Weimer  <fweimer@redhat.com>
+
 	* include/unistd.h (__have_dup3): Remove declaration.
 	* libio/freopen.c (freopen): Assume that O_CLOEXEC is defined and
 	dup3 is available.
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
index 1e9a6ee..c5d3e0e 100644
--- a/elf/dl-misc.c
+++ b/elf/dl-misc.c
@@ -45,11 +45,7 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
 {
   void *result = MAP_FAILED;
   struct stat64 st;
-  int flags = O_RDONLY;
-#ifdef O_CLOEXEC
-  flags |= O_CLOEXEC;
-#endif
-  int fd = __open (file, flags);
+  int fd = __open (file, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       if (__fxstat64 (_STAT_VER, fd, &st) >= 0)
diff --git a/include/fcntl.h b/include/fcntl.h
index 3b2c887..9a007c3 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -36,10 +36,6 @@ extern int __openat64_2 (int __fd, const char *__path, int __oflag);
 
 /* Flag determining whether the *at system calls are available.  */
 extern int __have_atfcts attribute_hidden;
-
-#ifdef O_CLOEXEC
-extern int __have_o_cloexec attribute_hidden;
-#endif
 #endif
 
 #endif
diff --git a/io/Makefile b/io/Makefile
index 333a049..95e04b2 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -55,8 +55,6 @@ routines :=								\
 	sendfile sendfile64 \
 	utimensat futimens
 
-aux := have_o_cloexec
-
 # These routines will be omitted from the libc shared object.
 # Instead the static object files will be included in a special archive
 # linked against when the shared library will be used.
diff --git a/io/have_o_cloexec.c b/io/have_o_cloexec.c
deleted file mode 100644
index 295eccc..0000000
--- a/io/have_o_cloexec.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright (C) 2007-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <fcntl.h>
-#include <kernel-features.h>
-
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-int __have_o_cloexec;
-#endif
diff --git a/libio/fileops.c b/libio/fileops.c
index f12ed16..c55e196 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -321,9 +321,7 @@ _IO_new_file_fopen (_IO_FILE *fp, const char *filename, const char *mode,
 	  fp->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 	  continue;
 	case 'e':
-#ifdef O_CLOEXEC
 	  oflags |= O_CLOEXEC;
-#endif
 	  fp->_flags2 |= _IO_FLAGS2_CLOEXEC;
 	  continue;
 	default:
@@ -338,20 +336,6 @@ _IO_new_file_fopen (_IO_FILE *fp, const char *filename, const char *mode,
 
   if (result != NULL)
     {
-#ifndef __ASSUME_O_CLOEXEC
-      if ((fp->_flags2 & _IO_FLAGS2_CLOEXEC) != 0 && __have_o_cloexec <= 0)
-	{
-	  int fd = _IO_fileno (fp);
-	  if (__have_o_cloexec == 0)
-	    {
-	      int flags = __fcntl (fd, F_GETFD);
-	      __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
-	    }
-	  if (__have_o_cloexec < 0)
-	    __fcntl (fd, F_SETFD, FD_CLOEXEC);
-	}
-#endif
-
       /* Test whether the mode string specifies the conversion.  */
       cs = strstr (last_recognized + 1, ",ccs=");
       if (cs != NULL)
diff --git a/libio/iopopen.c b/libio/iopopen.c
index 5887bd1..6f3a7b8 100644
--- a/libio/iopopen.c
+++ b/libio/iopopen.c
@@ -140,13 +140,11 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
   if (_IO_file_is_open (fp))
     return NULL;
 
-#ifdef O_CLOEXEC
-    {
-      int r = __pipe2 (pipe_fds, O_CLOEXEC);
-	if (r < 0)
-	  return NULL;
-    }
-#endif
+  {
+    int r = __pipe2 (pipe_fds, O_CLOEXEC);
+    if (r < 0)
+      return NULL;
+  }
 
   if (do_read)
     {
@@ -169,12 +167,10 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
 
       if (child_end != child_std_end)
 	_IO_dup2 (child_end, child_std_end);
-#ifdef O_CLOEXEC
       else
 	/* The descriptor is already the one we will use.  But it must
 	   not be marked close-on-exec.  Undo the effects.  */
 	__fcntl (child_end, F_SETFD, 0);
-#endif
       /* POSIX.2:  "popen() shall ensure that any streams from previous
          popen() calls that remain open in the parent process are closed
 	 in the new child process." */
@@ -200,11 +196,9 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
     }
 
   if (!do_cloexec)
-#ifdef O_CLOEXEC
     /* Undo the effects of the pipe2 call which set the
        close-on-exec flag.  */
     __fcntl (parent_end, F_SETFD, 0);
-#endif
 
   _IO_fileno (fp) = parent_end;
 
diff --git a/login/utmp_file.c b/login/utmp_file.c
index b1dfb3f..6ebe1ef 100644
--- a/login/utmp_file.c
+++ b/login/utmp_file.c
@@ -141,42 +141,11 @@ setutent_file (void)
 
       file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
 
-#ifdef O_CLOEXEC
-# define O_flags O_LARGEFILE | O_CLOEXEC
-#else
-# define O_flags O_LARGEFILE
-#endif
       file_writable = false;
-      file_fd = open_not_cancel_2 (file_name, O_RDONLY | O_flags);
+      file_fd = open_not_cancel_2
+	(file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
       if (file_fd == -1)
 	return 0;
-
-#ifndef __ASSUME_O_CLOEXEC
-# ifdef O_CLOEXEC
-      if (__have_o_cloexec <= 0)
-# endif
-	{
-	  /* We have to make sure the file is `closed on exec'.  */
-	  int result = fcntl_not_cancel (file_fd, F_GETFD, 0);
-	  if (result >= 0)
-	    {
-# ifdef O_CLOEXEC
-	      if (__have_o_cloexec == 0)
-		__have_o_cloexec = (result & FD_CLOEXEC) ? 1 : -1;
-
-	      if (__have_o_cloexec < 0)
-# endif
-		result = fcntl_not_cancel (file_fd, F_SETFD,
-					   result | FD_CLOEXEC);
-	    }
-
-	  if (result == -1)
-	    {
-	      close_not_cancel_no_status (file_fd);
-	      return 0;
-	    }
-	}
-#endif
     }
 
   __lseek64 (file_fd, 0, SEEK_SET);
@@ -404,37 +373,11 @@ pututline_file (const struct utmp *data)
       /* We must make the file descriptor writable before going on.  */
       const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
 
-      int new_fd = open_not_cancel_2 (file_name, O_RDWR | O_flags);
+      int new_fd = open_not_cancel_2
+	(file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC);
       if (new_fd == -1)
 	return NULL;
 
-#ifndef __ASSUME_O_CLOEXEC
-# ifdef O_CLOEXEC
-      if (__have_o_cloexec <= 0)
-# endif
-	{
-	  /* We have to make sure the file is `closed on exec'.  */
-	  int result = fcntl_not_cancel (file_fd, F_GETFD, 0);
-	  if (result >= 0)
-	    {
-# ifdef O_CLOEXEC
-	      if (__have_o_cloexec == 0)
-		__have_o_cloexec = (result & FD_CLOEXEC) ? 1 : -1;
-
-	      if (__have_o_cloexec < 0)
-# endif
-		result = fcntl_not_cancel (file_fd, F_SETFD,
-					   result | FD_CLOEXEC);
-	    }
-
-	  if (result == -1)
-	    {
-	      close_not_cancel_no_status (file_fd);
-	      return NULL;
-	    }
-	}
-#endif
-
       if (__lseek64 (new_fd, __lseek64 (file_fd, 0, SEEK_CUR), SEEK_SET) == -1
 	  || __dup2 (new_fd, file_fd) < 0)
 	{
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 800f2a8..02c53eb 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -300,15 +300,6 @@ mtrace (void)
       mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce");
       if (mallstream != NULL)
         {
-#ifndef __ASSUME_O_CLOEXEC
-          /* Make sure we close the file descriptor on exec.  */
-          int flags = __fcntl (fileno (mallstream), F_GETFD, 0);
-          if (flags >= 0)
-            {
-              flags |= FD_CLOEXEC;
-              __fcntl (fileno (mallstream), F_SETFD, flags);
-            }
-#endif
           /* Be sure it doesn't malloc its buffer!  */
           malloc_trace_buffer = mtb;
           setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
index e830a2f..0381458 100644
--- a/nis/nss_compat/compat-grp.c
+++ b/nis/nss_compat/compat-grp.c
@@ -70,19 +70,6 @@ static ent_t ext_ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
-/* Positive if O_CLOEXEC is supported, negative if it is not supported,
-   zero if it is still undecided.  This variable is shared with the
-   other compat functions.  */
-#ifdef __ASSUME_O_CLOEXEC
-# define __compat_have_cloexec 1
-#else
-# ifdef O_CLOEXEC
-int __compat_have_cloexec;
-# else
-#  define __compat_have_cloexec -1
-# endif
-#endif
-
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -125,43 +112,8 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
       if (ent->stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
-	{
-	  /* We have to make sure the file is  `closed on exec'.  */
-	  int result = 0;
-
-	  if (__compat_have_cloexec <= 0)
-	    {
-	      int flags;
-	      result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
-				      0);
-	      if (result >= 0)
-		{
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-		  if (__compat_have_cloexec == 0)
-		    __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
-
-		  if (__compat_have_cloexec < 0)
-#endif
-		    {
-		      flags |= FD_CLOEXEC;
-		      result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
-				      flags);
-		    }
-		}
-	    }
-
-	  if (result < 0)
-	    {
-	      /* Something went wrong.  Close the stream and return a
-	         failure.  */
-	      fclose (ent->stream);
-	      ent->stream = NULL;
-	      status = NSS_STATUS_UNAVAIL;
-	    }
-	  else
-	    /* We take care of locking ourself.  */
-	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
-	}
+	/* We take care of locking ourself.  */
+	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
     }
   else
     rewind (ent->stream);
diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
index 1b37e0c..7952134 100644
--- a/nis/nss_compat/compat-initgroups.c
+++ b/nis/nss_compat/compat-initgroups.c
@@ -77,20 +77,6 @@ struct ent_t
 };
 typedef struct ent_t ent_t;
 
-
-/* Positive if O_CLOEXEC is supported, negative if it is not supported,
-   zero if it is still undecided.  This variable is shared with the
-   other compat functions.  */
-#ifdef __ASSUME_O_CLOEXEC
-# define __compat_have_cloexec 1
-#else
-# ifdef O_CLOEXEC
-extern int __compat_have_cloexec;
-# else
-#  define __compat_have_cloexec -1
-# endif
-#endif
-
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -141,42 +127,8 @@ internal_setgrent (ent_t *ent)
   if (ent->stream == NULL)
     status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
   else
-    {
-      /* We have to make sure the file is  `closed on exec'.  */
-      int result = 0;
-
-      if (__compat_have_cloexec <= 0)
-	{
-	  int flags;
-	  result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
-	  if (result >= 0)
-	    {
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-	      if (__compat_have_cloexec == 0)
-		__compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
-
-	      if (__compat_have_cloexec < 0)
-#endif
-		{
-		  flags |= FD_CLOEXEC;
-		  result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
-				  flags);
-		}
-	    }
-	}
-
-      if (result < 0)
-	{
-	  /* Something went wrong.  Close the stream and return a
-	     failure.  */
-	  fclose (ent->stream);
-	  ent->stream = NULL;
-	  status = NSS_STATUS_UNAVAIL;
-	}
-      else
-	/* We take care of locking ourself.  */
-	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
-    }
+    /* We take care of locking ourself.  */
+    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
 
   return status;
 }
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
index 28ae7fb..0583a10 100644
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -80,19 +80,6 @@ static ent_t ext_ent = { false, false, true, NSS_STATUS_SUCCESS, NULL,
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
-/* Positive if O_CLOEXEC is supported, negative if it is not supported,
-   zero if it is still undecided.  This variable is shared with the
-   other compat functions.  */
-#ifdef __ASSUME_O_CLOEXEC
-# define __compat_have_cloexec 1
-#else
-# ifdef O_CLOEXEC
-extern int __compat_have_cloexec;
-# else
-#  define __compat_have_cloexec -1
-# endif
-#endif
-
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -240,43 +227,8 @@ internal_setpwent (ent_t *ent, int stayopen, int needent)
       if (ent->stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
-	{
-	  /* We have to make sure the file is  `closed on exec'.  */
-	  int result = 0;
-
-	  if (__compat_have_cloexec <= 0)
-	    {
-	      int flags;
-	      result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
-				      0);
-	      if (result >= 0)
-		{
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-		  if (__compat_have_cloexec == 0)
-		    __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
-
-		  if (__compat_have_cloexec < 0)
-#endif
-		    {
-		      flags |= FD_CLOEXEC;
-		      result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
-				      flags);
-		    }
-		}
-	    }
-
-	  if (result < 0)
-	    {
-	      /* Something went wrong.  Close the stream and return a
-	         failure.  */
-	      fclose (ent->stream);
-	      ent->stream = NULL;
-	      status = NSS_STATUS_UNAVAIL;
-	    }
-	  else
-	    /* We take care of locking ourself.  */
-	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
-	}
+	/* We take care of locking ourself.  */
+	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
     }
   else
     rewind (ent->stream);
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index 550444c..eec3af3 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -77,19 +77,6 @@ static ent_t ext_ent = { false, true, false, NSS_STATUS_SUCCESS, NULL,
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
-/* Positive if O_CLOEXEC is supported, negative if it is not supported,
-   zero if it is still undecided.  This variable is shared with the
-   other compat functions.  */
-#ifdef __ASSUME_O_CLOEXEC
-# define __compat_have_cloexec 1
-#else
-# ifdef O_CLOEXEC
-extern int __compat_have_cloexec;
-# else
-#  define __compat_have_cloexec -1
-# endif
-#endif
-
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -196,43 +183,8 @@ internal_setspent (ent_t *ent, int stayopen, int needent)
       if (ent->stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
-	{
-	  /* We have to make sure the file is  `closed on exec'.  */
-	  int result = 0;
-
-	  if (__compat_have_cloexec <= 0)
-	    {
-	      int flags;
-	      result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
-				      0);
-	      if (result >= 0)
-		{
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-		  if (__compat_have_cloexec == 0)
-		    __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
-
-		  if (__compat_have_cloexec < 0)
-#endif
-		    {
-		      flags |= FD_CLOEXEC;
-		      result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
-				      flags);
-		    }
-		}
-	    }
-
-	  if (result < 0)
-	    {
-	      /* Something went wrong.  Close the stream and return a
-	         failure.  */
-	      fclose (ent->stream);
-	      ent->stream = NULL;
-	      status = NSS_STATUS_UNAVAIL;
-	    }
-	  else
-	    /* We take care of locking ourself.  */
-	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
-	}
+	/* We take care of locking ourself.  */
+	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
     }
   else
     rewind (ent->stream);
diff --git a/nscd/connections.c b/nscd/connections.c
index 205ff42..a5ca57a 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -499,13 +499,6 @@ fail:
 }
 
 
-#ifdef O_CLOEXEC
-# define EXTRA_O_FLAGS O_CLOEXEC
-#else
-# define EXTRA_O_FLAGS 0
-#endif
-
-
 /* Initialize database information structures.  */
 void
 nscd_init (void)
@@ -528,7 +521,7 @@ nscd_init (void)
 	if (dbs[cnt].persistent)
 	  {
 	    /* Try to open the appropriate file on disk.  */
-	    int fd = open (dbs[cnt].db_filename, O_RDWR | EXTRA_O_FLAGS);
+	    int fd = open (dbs[cnt].db_filename, O_RDWR | O_CLOEXEC);
 	    if (fd != -1)
 	      {
 		char *msg = NULL;
@@ -608,7 +601,7 @@ nscd_init (void)
 		    if (dbs[cnt].shared)
 		      {
 			dbs[cnt].ro_fd = open (dbs[cnt].db_filename,
-					       O_RDONLY | EXTRA_O_FLAGS);
+					       O_RDONLY | O_CLOEXEC);
 			if (dbs[cnt].ro_fd == -1)
 			  dbg_log (_("\
 cannot create read-only descriptor for \"%s\"; no mmap"),
@@ -648,23 +641,23 @@ cannot create read-only descriptor for \"%s\"; no mmap"),
 	    if (dbs[cnt].persistent)
 	      {
 		fd = open (dbs[cnt].db_filename,
-			   O_RDWR | O_CREAT | O_EXCL | O_TRUNC | EXTRA_O_FLAGS,
+			   O_RDWR | O_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC,
 			   S_IRUSR | S_IWUSR);
 		if (fd != -1 && dbs[cnt].shared)
 		  ro_fd = open (dbs[cnt].db_filename,
-				O_RDONLY | EXTRA_O_FLAGS);
+				O_RDONLY | O_CLOEXEC);
 	      }
 	    else
 	      {
 		char fname[] = _PATH_NSCD_XYZ_DB_TMP;
-		fd = mkostemp (fname, EXTRA_O_FLAGS);
+		fd = mkostemp (fname, O_CLOEXEC);
 
 		/* We do not need the file name anymore after we
 		   opened another file descriptor in read-only mode.  */
 		if (fd != -1)
 		  {
 		    if (dbs[cnt].shared)
-		      ro_fd = open (fname, O_RDONLY | EXTRA_O_FLAGS);
+		      ro_fd = open (fname, O_RDONLY | O_CLOEXEC);
 
 		    unlink (fname);
 		  }
@@ -782,24 +775,6 @@ cannot create read-only descriptor for \"%s\"; no mmap"),
 	      }
 	  }
 
-#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
-	/* We do not check here whether the O_CLOEXEC provided to the
-	   open call was successful or not.  The two fcntl calls are
-	   only performed once each per process start-up and therefore
-	   is not noticeable at all.  */
-	if (paranoia
-	    && ((dbs[cnt].wr_fd != -1
-		 && fcntl (dbs[cnt].wr_fd, F_SETFD, FD_CLOEXEC) == -1)
-		|| (dbs[cnt].ro_fd != -1
-		    && fcntl (dbs[cnt].ro_fd, F_SETFD, FD_CLOEXEC) == -1)))
-	  {
-	    dbg_log (_("\
-cannot set socket to close on exec: %s; disabling paranoia mode"),
-		     strerror (errno));
-	    paranoia = 0;
-	  }
-#endif
-
 	if (dbs[cnt].head == NULL)
 	  {
 	    /* We do not use the persistent database.  Just
diff --git a/nss/Makefile b/nss/Makefile
index de6c47a..fa0418e 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -74,7 +74,7 @@ vpath %.c $(subdir-dirs) ../locale/programs ../intl
 
 
 libnss_files-routines	:= $(addprefix files-,$(databases)) \
-			   files-initgroups files-have_o_cloexec files-init
+			   files-initgroups files-init
 
 libnss_db-dbs		:= $(addprefix db-,\
 				       $(filter-out hosts network key alias,\
diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c
index 42ce00f..1c58bd1 100644
--- a/nss/nss_db/db-open.c
+++ b/nss/nss_db/db-open.c
@@ -36,11 +36,7 @@ internal_setent (const char *file, struct nss_db_map *mapping)
 {
   enum nss_status status = NSS_STATUS_UNAVAIL;
 
-  int mode = O_RDONLY | O_LARGEFILE;
-#ifdef O_CLOEXEC
-  mode |= O_CLOEXEC;
-#endif
-  int fd = open_not_cancel_2 (file, mode);
+  int fd = open_not_cancel_2 (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
   if (fd != -1)
     {
       struct nss_db_header header;
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
index dbd38a3..265331e 100644
--- a/nss/nss_files/files-XXX.c
+++ b/nss/nss_files/files-XXX.c
@@ -78,41 +78,6 @@ internal_setent (FILE **stream)
 
       if (*stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
-      else
-	{
-#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
-# ifdef O_CLOEXEC
-	  if (__have_o_cloexec <= 0)
-# endif
-	    {
-	      /* We have to make sure the file is  `closed on exec'.  */
-	      int result;
-	      int flags;
-
-	      result = flags = fcntl (fileno (*stream), F_GETFD, 0);
-	      if (result >= 0)
-		{
-# ifdef O_CLOEXEC
-		  if (__have_o_cloexec == 0)
-		    __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
-		  if (__have_o_cloexec < 0)
-# endif
-		    {
-		      flags |= FD_CLOEXEC;
-		      result = fcntl (fileno (*stream), F_SETFD, flags);
-		    }
-		}
-	      if (result < 0)
-		{
-		  /* Something went wrong.  Close the stream and return a
-		     failure.  */
-		  fclose (*stream);
-		  *stream = NULL;
-		  status = NSS_STATUS_UNAVAIL;
-		}
-	    }
-#endif
-	}
     }
   else
     rewind (*stream);
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index de4e364..cf872bb 100644
--- a/nss/nss_files/files-alias.c
+++ b/nss/nss_files/files-alias.c
@@ -51,41 +51,6 @@ internal_setent (FILE **stream)
 
       if (*stream == NULL)
 	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
-      else
-	{
-#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
-# ifdef O_CLOEXEC
-	  if (__have_o_cloexec <= 0)
-# endif
-	    {
-	      /* We have to make sure the file is  `closed on exec'.  */
-	      int result;
-	      int flags;
-
-	      result = flags = fcntl (fileno (*stream), F_GETFD, 0);
-	      if (result >= 0)
-		{
-# ifdef O_CLOEXEC
-		  if (__have_o_cloexec == 0)
-		    __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
-		  if (__have_o_cloexec < 0)
-# endif
-		    {
-		      flags |= FD_CLOEXEC;
-		      result = fcntl (fileno (*stream), F_SETFD, flags);
-		    }
-		}
-	      if (result < 0)
-		{
-		  /* Something went wrong.  Close the stream and return a
-		     failure.  */
-		  fclose (*stream);
-		  stream = NULL;
-		  status = NSS_STATUS_UNAVAIL;
-		}
-	    }
-#endif
-	}
     }
   else
     rewind (*stream);
diff --git a/nss/nss_files/files-have_o_cloexec.c b/nss/nss_files/files-have_o_cloexec.c
deleted file mode 100644
index 295eccc..0000000
--- a/nss/nss_files/files-have_o_cloexec.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright (C) 2007-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <fcntl.h>
-#include <kernel-features.h>
-
-#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
-int __have_o_cloexec;
-#endif
diff --git a/posix/wordexp.c b/posix/wordexp.c
index 639d73e..ee83838 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -833,12 +833,8 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
       __close (fildes[1]);
     }
   else
-    {
-#ifdef O_CLOEXEC
-      /* Reset the close-on-exec flag (if necessary).  */
-      __fcntl (fildes[1], F_SETFD, 0);
-#endif
-    }
+    /* Reset the close-on-exec flag (if necessary).  */
+    __fcntl (fildes[1], F_SETFD, 0);
 
   /* Redirect stderr to /dev/null if we have to.  */
   if (showerr == 0)
@@ -902,14 +898,12 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
   if (!comm || !*comm)
     return 0;
 
-#ifdef O_CLOEXEC
   {
     int r = __pipe2 (fildes, O_CLOEXEC);
     if (r < 0)
       /* Bad */
       return WRDE_NOSPACE;
   }
-#endif
 
  again:
   if ((pid = __fork ()) < 0)
diff --git a/shadow/lckpwdf.c b/shadow/lckpwdf.c
index 5e9a976..09427eb 100644
--- a/shadow/lckpwdf.c
+++ b/shadow/lckpwdf.c
@@ -96,39 +96,12 @@ __lckpwdf (void)
   /* Prevent problems caused by multiple threads.  */
   __libc_lock_lock (lock);
 
-  int oflags = O_WRONLY | O_CREAT;
-#ifdef O_CLOEXEC
-  oflags |= O_CLOEXEC;
-#endif
+  int oflags = O_WRONLY | O_CREAT | O_CLOEXEC;
   lock_fd = __open (PWD_LOCKFILE, oflags, 0600);
   if (lock_fd == -1)
     /* Cannot create lock file.  */
     RETURN_CLOSE_FD (-1);
 
-#ifndef __ASSUME_O_CLOEXEC
-# ifdef O_CLOEXEC
-  if (__have_o_cloexec <= 0)
-# endif
-    {
-      /* Make sure file gets correctly closed when process finished.  */
-      int flags = __fcntl (lock_fd, F_GETFD, 0);
-      if (flags == -1)
-	/* Cannot get file flags.  */
-	RETURN_CLOSE_FD (-1);
-# ifdef O_CLOEXEC
-      if (__have_o_cloexec == 0)
-	__have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
-      if (__have_o_cloexec < 0)
-# endif
-	{
-	  flags |= FD_CLOEXEC;		/* Close on exit.  */
-	  if (__fcntl (lock_fd, F_SETFD, flags) < 0)
-	    /* Cannot set new flags.  */
-	    RETURN_CLOSE_FD (-1);
-	}
-    }
-#endif
-
   /* Now we have to get exclusive write access.  Since multiple
      process could try this we won't stop when it first fails.
      Instead we set a timeout for the system call.  Once the timer
diff --git a/sysdeps/mach/hurd/kernel-features.h b/sysdeps/mach/hurd/kernel-features.h
index 60c5bca..20cb3ba 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 4a5808b..32834fd 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 0246e91..eb1706a 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 75d833a..909aa61 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 56a9965..64315de 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 e0eb4e2..fd936c5 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
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=18efac1c735a005c14c3da1101c26945ac5f80f6

commit 18efac1c735a005c14c3da1101c26945ac5f80f6
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu Apr 13 20:53:43 2017 +0200

    Assume that dup3 is available

diff --git a/ChangeLog b/ChangeLog
index 4c86f8c..b178f10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2017-04-13  Florian Weimer  <fweimer@redhat.com>
 
+	* include/unistd.h (__have_dup3): Remove declaration.
+	* libio/freopen.c (freopen): Assume that O_CLOEXEC is defined and
+	dup3 is available.
+	* libio/freopen64.c (freopen64): Likewise.
+	* socket/Makefile (aux): Remove have_sock_cloexec.
+	* socket/have_sock_cloexec.c: Remove file.
+	* sysdeps/mach/hurd/kernel-features.h (__ASSUME_DUP3): Remove
+	definition.
+	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_DUP3):
+	Likewise.
+	* sysdeps/nacl/kernel-features.h: Update comment.
+
+2017-04-13  Florian Weimer  <fweimer@redhat.com>
+
 	* include/unistd.h (__have_pipe2): Remove declaration.
 	* socket/have_sock_cloexec.c (__have_pipe2): Remove definition.
 	* libio/iopopen.c (_IO_new_proc_open): Assume that pipe2 is
diff --git a/include/unistd.h b/include/unistd.h
index e15fa0e..16a8815 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -171,8 +171,6 @@ extern int __libc_pause (void);
 /* Not cancelable variant.  */
 extern int __pause_nocancel (void) attribute_hidden;
 
-extern int __have_dup3 attribute_hidden;
-
 extern int __getlogin_r_loginuid (char *name, size_t namesize)
      attribute_hidden;
 
diff --git a/libio/freopen.c b/libio/freopen.c
index 03e3ae7..ad1c848 100644
--- a/libio/freopen.c
+++ b/libio/freopen.c
@@ -78,32 +78,9 @@ freopen (const char *filename, const char *mode, FILE *fp)
 
       if (fd != -1)
 	{
-#ifdef O_CLOEXEC
-# ifndef __ASSUME_DUP3
-	  int newfd;
-	  if (__have_dup3 < 0)
-	    newfd = -1;
-	  else
-	    newfd =
-# endif
-	      __dup3 (_IO_fileno (result), fd,
-                      (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
-                      ? O_CLOEXEC : 0);
-#else
-# define newfd 1
-#endif
-
-#ifndef __ASSUME_DUP3
-	  if (newfd < 0)
-	    {
-	      if (errno == ENOSYS)
-		__have_dup3 = -1;
-
-	      __dup2 (_IO_fileno (result), fd);
-	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
-		__fcntl (fd, F_SETFD, FD_CLOEXEC);
-	    }
-#endif
+	  __dup3 (_IO_fileno (result), fd,
+		  (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
+		  ? O_CLOEXEC : 0);
 	  __close (_IO_fileno (result));
 	  _IO_fileno (result) = fd;
 	}
diff --git a/libio/freopen64.c b/libio/freopen64.c
index 1f0d8ab..adf749a 100644
--- a/libio/freopen64.c
+++ b/libio/freopen64.c
@@ -61,32 +61,9 @@ freopen64 (const char *filename, const char *mode, FILE *fp)
 
       if (fd != -1)
 	{
-#ifdef O_CLOEXEC
-# ifndef __ASSUME_DUP3
-	  int newfd;
-	  if (__have_dup3 < 0)
-	    newfd = -1;
-	  else
-	    newfd =
-# endif
-	      __dup3 (_IO_fileno (result), fd,
-                      (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
-                      ? O_CLOEXEC : 0);
-#else
-# define newfd 1
-#endif
-
-#ifndef __ASSUME_DUP3
-	  if (newfd < 0)
-	    {
-	      if (errno == ENOSYS)
-		__have_dup3 = -1;
-
-	      __dup2 (_IO_fileno (result), fd);
-	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
-		__fcntl (fd, F_SETFD, FD_CLOEXEC);
-	    }
-#endif
+	  __dup3 (_IO_fileno (result), fd,
+		  (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
+		  ? O_CLOEXEC : 0);
 	  __close (_IO_fileno (result));
 	  _IO_fileno (result) = fd;
 	}
diff --git a/socket/Makefile b/socket/Makefile
index c299d34..25d4f68 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -31,6 +31,6 @@ routines := accept bind connect getpeername getsockname getsockopt	\
 	    setsockopt shutdown socket socketpair isfdtype opensock	\
 	    sockatmark accept4 recvmmsg sendmmsg
 
-aux	 := have_sock_cloexec sa_len
+aux	 := sa_len
 
 include ../Rules
diff --git a/socket/have_sock_cloexec.c b/socket/have_sock_cloexec.c
deleted file mode 100644
index 579577d..0000000
--- a/socket/have_sock_cloexec.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (C) 2008-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <kernel-features.h>
-
-#if defined O_CLOEXEC && !defined __ASSUME_DUP3
-int __have_dup3;
-#endif
diff --git a/sysdeps/mach/hurd/kernel-features.h b/sysdeps/mach/hurd/kernel-features.h
index 687c7f0..60c5bca 100644
--- a/sysdeps/mach/hurd/kernel-features.h
+++ b/sysdeps/mach/hurd/kernel-features.h
@@ -21,5 +21,4 @@
    But those referring to POSIX-level features like O_* flags can be.  */
 
 #define __ASSUME_O_CLOEXEC	1
-#define __ASSUME_DUP3		1
 #define __ASSUME_ACCEPT4	1
diff --git a/sysdeps/nacl/kernel-features.h b/sysdeps/nacl/kernel-features.h
index 38a47f1..4a5808b 100644
--- a/sysdeps/nacl/kernel-features.h
+++ b/sysdeps/nacl/kernel-features.h
@@ -23,6 +23,5 @@
 #define __ASSUME_O_CLOEXEC	1
 
 /*
-#define __ASSUME_DUP3		1
 #define __ASSUME_ACCEPT4	1
 */
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 233e302..e0eb4e2 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -74,7 +74,6 @@
 /* Support for various CLOEXEC and NONBLOCK flags was added in
    2.6.27.  */
 #define __ASSUME_IN_NONBLOCK	1
-#define __ASSUME_DUP3		1
 
 /* Support for accept4 functionality was added in 2.6.28, but for some
    architectures using a separate syscall rather than socketcall that

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=50f6c198bd55b0706501f7a8316d166f8be24e10

commit 50f6c198bd55b0706501f7a8316d166f8be24e10
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu Apr 13 17:22:59 2017 +0200

    Assume that pipe2 is always available
    
    The Debian patches (which are already required to build glibc before
    this commit) contain an implementation of pipe2.

diff --git a/ChangeLog b/ChangeLog
index b209f9c..4c86f8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-04-13  Florian Weimer  <fweimer@redhat.com>
 
+	* include/unistd.h (__have_pipe2): Remove declaration.
+	* socket/have_sock_cloexec.c (__have_pipe2): Remove definition.
+	* libio/iopopen.c (_IO_new_proc_open): Assume that pipe2 is
+	available.
+	* posix/wordexp.c (exec_comm_child, exec_comm): Likewise.
+	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_PIPE2):
+	Remove definition.
+
+2017-04-13  Florian Weimer  <fweimer@redhat.com>
+
 	* csu/check_fds.c (__libc_check_standard_fds): Assume O_NOFOLLOW
 	is defined.
 	* elf/rtld.c (process_envvars): Likewise.
diff --git a/include/unistd.h b/include/unistd.h
index 16d68a1..e15fa0e 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -171,7 +171,6 @@ extern int __libc_pause (void);
 /* Not cancelable variant.  */
 extern int __pause_nocancel (void) attribute_hidden;
 
-extern int __have_pipe2 attribute_hidden;
 extern int __have_dup3 attribute_hidden;
 
 extern int __getlogin_r_loginuid (char *name, size_t namesize)
diff --git a/libio/iopopen.c b/libio/iopopen.c
index 08e29b4..5887bd1 100644
--- a/libio/iopopen.c
+++ b/libio/iopopen.c
@@ -141,28 +141,12 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
     return NULL;
 
 #ifdef O_CLOEXEC
-# ifndef __ASSUME_PIPE2
-  if (__have_pipe2 >= 0)
-# endif
     {
       int r = __pipe2 (pipe_fds, O_CLOEXEC);
-# ifndef __ASSUME_PIPE2
-      if (__have_pipe2 == 0)
-	__have_pipe2 = r != -1 || errno != ENOSYS ? 1 : -1;
-
-      if (__have_pipe2 > 0)
-# endif
 	if (r < 0)
 	  return NULL;
     }
 #endif
-#ifndef __ASSUME_PIPE2
-# ifdef O_CLOEXEC
-  if (__have_pipe2 < 0)
-# endif
-    if (__pipe (pipe_fds) < 0)
-      return NULL;
-#endif
 
   if (do_read)
     {
@@ -183,27 +167,13 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
       int child_std_end = do_read ? 1 : 0;
       struct _IO_proc_file *p;
 
-#ifndef __ASSUME_PIPE2
-      /* If we have pipe2 the descriptor is marked for close-on-exec.  */
-      _IO_close (parent_end);
-#endif
       if (child_end != child_std_end)
-	{
-	  _IO_dup2 (child_end, child_std_end);
-#ifndef __ASSUME_PIPE2
-	  _IO_close (child_end);
-#endif
-	}
+	_IO_dup2 (child_end, child_std_end);
 #ifdef O_CLOEXEC
       else
-	{
-	  /* The descriptor is already the one we will use.  But it must
-	     not be marked close-on-exec.  Undo the effects.  */
-# ifndef __ASSUME_PIPE2
-	  if (__have_pipe2 > 0)
-# endif
-	    __fcntl (child_end, F_SETFD, 0);
-	}
+	/* The descriptor is already the one we will use.  But it must
+	   not be marked close-on-exec.  Undo the effects.  */
+	__fcntl (child_end, F_SETFD, 0);
 #endif
       /* POSIX.2:  "popen() shall ensure that any streams from previous
          popen() calls that remain open in the parent process are closed
@@ -229,26 +199,12 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
       return NULL;
     }
 
-  if (do_cloexec)
-    {
-#ifndef __ASSUME_PIPE2
-# ifdef O_CLOEXEC
-      if (__have_pipe2 < 0)
-# endif
-	__fcntl (parent_end, F_SETFD, FD_CLOEXEC);
-#endif
-    }
-  else
-    {
+  if (!do_cloexec)
 #ifdef O_CLOEXEC
-      /* Undo the effects of the pipe2 call which set the
-	 close-on-exec flag.  */
-# ifndef __ASSUME_PIPE2
-      if (__have_pipe2 > 0)
-# endif
-	__fcntl (parent_end, F_SETFD, 0);
+    /* Undo the effects of the pipe2 call which set the
+       close-on-exec flag.  */
+    __fcntl (parent_end, F_SETFD, 0);
 #endif
-    }
 
   _IO_fileno (fp) = parent_end;
 
diff --git a/posix/wordexp.c b/posix/wordexp.c
index ba3f3ed..639d73e 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -836,10 +836,7 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
     {
 #ifdef O_CLOEXEC
       /* Reset the close-on-exec flag (if necessary).  */
-# ifndef __ASSUME_PIPE2
-      if (__have_pipe2 > 0)
-# endif
-	__fcntl (fildes[1], F_SETFD, 0);
+      __fcntl (fildes[1], F_SETFD, 0);
 #endif
     }
 
@@ -906,29 +903,12 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
     return 0;
 
 #ifdef O_CLOEXEC
-# ifndef __ASSUME_PIPE2
-  if (__have_pipe2 >= 0)
-# endif
-    {
-      int r = __pipe2 (fildes, O_CLOEXEC);
-# ifndef __ASSUME_PIPE2
-      if (__have_pipe2 == 0)
-	__have_pipe2 = r != -1 || errno != ENOSYS ? 1 : -1;
-
-      if (__have_pipe2 > 0)
-# endif
-	if (r < 0)
-	  /* Bad */
-	  return WRDE_NOSPACE;
-    }
-#endif
-#ifndef __ASSUME_PIPE2
-# ifdef O_CLOEXEC
-  if (__have_pipe2 < 0)
-# endif
-    if (__pipe (fildes) < 0)
+  {
+    int r = __pipe2 (fildes, O_CLOEXEC);
+    if (r < 0)
       /* Bad */
       return WRDE_NOSPACE;
+  }
 #endif
 
  again:
diff --git a/socket/have_sock_cloexec.c b/socket/have_sock_cloexec.c
index 70c730e..579577d 100644
--- a/socket/have_sock_cloexec.c
+++ b/socket/have_sock_cloexec.c
@@ -19,10 +19,6 @@
 #include <sys/socket.h>
 #include <kernel-features.h>
 
-#if defined O_CLOEXEC && !defined __ASSUME_PIPE2
-int __have_pipe2;
-#endif
-
 #if defined O_CLOEXEC && !defined __ASSUME_DUP3
 int __have_dup3;
 #endif
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index e6a2720..233e302 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -74,7 +74,6 @@
 /* Support for various CLOEXEC and NONBLOCK flags was added in
    2.6.27.  */
 #define __ASSUME_IN_NONBLOCK	1
-#define __ASSUME_PIPE2		1
 #define __ASSUME_DUP3		1
 
 /* Support for accept4 functionality was added in 2.6.28, but for some

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]