From abb3587fe939d469a44f2097bae361aabd269f3f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 5 Sep 2009 22:04:36 +0200 Subject: CLOEXEC: use open(CLOEXEC) if exist; do not check fcntl(FD_CLOEXEC) failure text data bss dec hex filename - 370 0 0 370 172 libc/misc/dirent/opendir.o + 366 0 0 366 16e libc/misc/dirent/opendir.o - 375 4 0 379 17b libc/pwd_grp/lckpwdf.o + 356 4 0 360 168 libc/pwd_grp/lckpwdf.o - 248 0 0 248 f8 librt/shm.o + 209 0 0 209 d1 librt/shm.o Signed-off-by: Denys Vlasenko --- librt/shm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'librt') diff --git a/librt/shm.c b/librt/shm.c index f1ef0e708..f0a974059 100644 --- a/librt/shm.c +++ b/librt/shm.c @@ -71,13 +71,16 @@ int shm_open(const char *name, int oflag, mode_t mode) #else fd = open(shm_name, oflag, mode); if (fd >= 0) { - int fdflags = fcntl(fd, F_GETFD, 0); - if (fdflags >= 0) - fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); - if (fdflags < 0) { - close(fd); - fd = -1; - } + fcntl(fd, F_SETFD, FD_CLOEXEC); + // thus far, {G,S}ETFD only has this single flag, + // and setting it never fails. + //int fdflags = fcntl(fd, F_GETFD); + //if (fdflags >= 0) + // fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); + //if (fdflags < 0) { + // close(fd); + // fd = -1; + //} } #endif old_errno = errno; -- cgit v1.2.3