aboutsummaryrefslogtreecommitdiff
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
parentb48061e1a534a2421c65e4258418d41a5335ba32 (diff)
downloadglibc-cef9b65376a044309f74b77860ccf3c48a4ae315.tar.xz
glibc-cef9b65376a044309f74b77860ccf3c48a4ae315.zip
Assume that O_CLOEXEC is always defined and works
-rw-r--r--ChangeLog56
-rw-r--r--elf/dl-misc.c6
-rw-r--r--include/fcntl.h4
-rw-r--r--io/Makefile2
-rw-r--r--io/have_o_cloexec.c23
-rw-r--r--libio/fileops.c16
-rw-r--r--libio/iopopen.c2
-rw-r--r--login/utmp_file.c65
-rw-r--r--malloc/mtrace.c9
-rw-r--r--nis/nss_compat/compat-grp.c52
-rw-r--r--nis/nss_compat/compat-initgroups.c52
-rw-r--r--nis/nss_compat/compat-pwd.c52
-rw-r--r--nis/nss_compat/compat-spwd.c52
-rw-r--r--nscd/connections.c37
-rw-r--r--nss/Makefile2
-rw-r--r--nss/nss_db/db-open.c6
-rw-r--r--nss/nss_files/files-XXX.c35
-rw-r--r--nss/nss_files/files-alias.c35
-rw-r--r--nss/nss_files/files-have_o_cloexec.c23
-rw-r--r--posix/wordexp.c8
-rw-r--r--shadow/lckpwdf.c29
-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
27 files changed, 91 insertions, 565 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a8ea7d303..ce6f13d179 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,61 @@
2017-04-18 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): 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-18 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 1e9a6ee560..c5d3e0e7c5 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 3b2c887146..9a007c358c 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 333a049d2b..95e04b241b 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 295ecccb77..0000000000
--- 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 f12ed16e30..c55e196dd8 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 95a12c90b5..b78e7e5ef2 100644
--- a/libio/iopopen.c
+++ b/libio/iopopen.c
@@ -173,12 +173,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." */
diff --git a/login/utmp_file.c b/login/utmp_file.c
index b1dfb3f644..6ebe1ef123 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 800f2a827a..02c53eb9fe 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 e830a2f0a2..0381458c0c 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 1b37e0c295..795213448c 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 28ae7fba84..0583a10b84 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. */
- __fsetloc