From 85ff35126623e6f26c84d9fa8a35b6762aefb110 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 10 Jul 2015 22:09:15 -0700 Subject: Revamp the CLOEXEC support in Qt The pipe2/dup3/accept4 functions and SOCK_CLOEXEC are quite old nowadays on Linux. They were introduced on Linux 2.6.28 and glibc 2.10, all from 2008. They were also picked up by uClibc in 2011 and FreeBSD as of version 10.0. So we no longer need the runtime detection of whether the feature is available. Instead, if the libc has support for it, use it unconditionally and fail at runtime if the syscall isn't implemented. Change-Id: Ib056b47dde3341ef9a52ffff13efcc39ef8dff7d Reviewed-by: Oswald Buddenhagen --- src/network/socket/qnet_unix_p.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/network/socket/qnet_unix_p.h') diff --git a/src/network/socket/qnet_unix_p.h b/src/network/socket/qnet_unix_p.h index cd118afd63..a5a87fc7c1 100644 --- a/src/network/socket/qnet_unix_p.h +++ b/src/network/socket/qnet_unix_p.h @@ -77,15 +77,13 @@ static inline int qt_safe_socket(int domain, int type, int protocol, int flags = Q_ASSERT((flags & ~O_NONBLOCK) == 0); int fd; -#if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) +#ifdef QT_THREADSAFE_CLOEXEC int newtype = type | SOCK_CLOEXEC; if (flags & O_NONBLOCK) newtype |= SOCK_NONBLOCK; fd = ::socket(domain, newtype, protocol); - if (fd != -1 || errno != EINVAL) - return fd; -#endif - + return fd; +#else fd = ::socket(domain, type, protocol); if (fd == -1) return -1; @@ -97,6 +95,7 @@ static inline int qt_safe_socket(int domain, int type, int protocol, int flags = ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK); return fd; +#endif } // Tru64 redefines accept -> _accept with _XOPEN_SOURCE_EXTENDED @@ -105,16 +104,14 @@ static inline int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *add Q_ASSERT((flags & ~O_NONBLOCK) == 0); int fd; -#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) +#ifdef QT_THREADSAFE_CLOEXEC // use accept4 int sockflags = SOCK_CLOEXEC; if (flags & O_NONBLOCK) sockflags |= SOCK_NONBLOCK; fd = ::accept4(s, addr, static_cast(addrlen), sockflags); - if (fd != -1 || !(errno == ENOSYS || errno == EINVAL)) - return fd; -#endif - + return fd; +#else fd = ::accept(s, addr, static_cast(addrlen)); if (fd == -1) return -1; @@ -126,6 +123,7 @@ static inline int qt_safe_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *add ::fcntl(fd, F_SETFL, ::fcntl(fd, F_GETFL) | O_NONBLOCK); return fd; +#endif } // UnixWare 7 redefines listen -> _listen -- cgit v1.2.3