summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-04 08:37:39 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-04 14:29:33 (GMT)
commit6d9143ebffc10a58d8d62e57e3378adae4af92cd (patch)
tree3fb60f7842dfdec4698ff726ac30a3a3b197abbe /src
parent47c191d3c6b9c3fbe062068167888bed434ab6e2 (diff)
downloadQt-6d9143ebffc10a58d8d62e57e3378adae4af92cd.zip
Qt-6d9143ebffc10a58d8d62e57e3378adae4af92cd.tar.gz
Qt-6d9143ebffc10a58d8d62e57e3378adae4af92cd.tar.bz2
Don't try to make direct system calls on Linux.
Accept that we cannot do everything, so users using outdated toolchains may have threading problems (leaking file descriptors). It's not like this is a recent problem anyway... Reviewed-By: Bradley T. Hughes
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcore_unix.cpp73
-rw-r--r--src/corelib/kernel/qcore_unix_p.h34
-rw-r--r--src/network/socket/qnet_unix_p.h2
3 files changed, 10 insertions, 99 deletions
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp
index b57d385..efa9c6d 100644
--- a/src/corelib/kernel/qcore_unix.cpp
+++ b/src/corelib/kernel/qcore_unix.cpp
@@ -161,76 +161,3 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
}
QT_END_NAMESPACE
-
-#ifdef Q_OS_LINUX
-// Don't wait for libc to supply the calls we need
-// Make syscalls directly
-
-# if defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0204
-// glibc 2.4 has syscall(...)
-# include <sys/syscall.h>
-# include <asm/unistd.h>
-# else
-// no syscall(...)
-static inline int syscall(...) { errno = ENOSYS; return -1;}
-# endif
-
-# ifndef __NR_dup3
-# if defined(__i386__)
-# define __NR_dup3 330
-# define __NR_pipe2 331
-# elif defined(__x86_64__)
-# define __NR_dup3 292
-# define __NR_pipe2 293
-# elif defined(__ia64__)
-# define __NR_dup3 1316
-# define __NR_pipe2 1317
-# else
-// set the syscalls to absurd numbers so that they'll cause ENOSYS errors
-# warning "Please port the pipe2/dup3 code to this platform"
-# define __NR_dup3 -1
-# define __NR_pipe2 -1
-# endif
-# endif
-
-# if !defined(__NR_socketcall) && !defined(__NR_accept4)
-# if defined(__x86_64__)
-# define __NR_accept4 288
-# elif defined(__ia64__)
-// not assigned yet to IA-64
-# define __NR_accept4 -1
-# else
-// set the syscalls to absurd numbers so that they'll cause ENOSYS errors
-# warning "Please port the accept4 code to this platform"
-# define __NR_accept4 -1
-# endif
-# endif
-
-QT_BEGIN_NAMESPACE
-namespace QtLibcSupplement {
- int pipe2(int pipes[], int flags)
- {
- return syscall(__NR_pipe2, pipes, flags);
- }
-
- int dup3(int oldfd, int newfd, int flags)
- {
- return syscall(__NR_dup3, oldfd, newfd, flags);
- }
-
- int accept4(int s, sockaddr *addr, QT_SOCKLEN_T *addrlen, int flags)
- {
-# if defined(__NR_socketcall)
- // This platform uses socketcall() instead of raw syscalls
- // the SYS_ACCEPT4 number is cross-platform: 18
- return syscall(__NR_socketcall, 18, &s);
-# else
- return syscall(__NR_accept4, s, addr, addrlen, flags);
-# endif
-
- Q_UNUSED(addr); Q_UNUSED(addrlen); Q_UNUSED(flags); // they're actually used
- }
-}
-QT_END_NAMESPACE
-#endif // Q_OS_LINUX
-
diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h
index 69ebb05..3bdd5ec 100644
--- a/src/corelib/kernel/qcore_unix_p.h
+++ b/src/corelib/kernel/qcore_unix_p.h
@@ -73,32 +73,16 @@
struct sockaddr;
-#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0204
-// Linux supports thread-safe FD_CLOEXEC
+#if defined(Q_OS_LINUX) && defined(O_CLOEXEC)
# define QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC 1
-
-// add defines for the consts for Linux
-# ifndef O_CLOEXEC
-# define O_CLOEXEC 02000000
-# endif
-# ifndef FD_DUPFD_CLOEXEC
-# define F_DUPFD_CLOEXEC 1030
-# endif
-# ifndef SOCK_CLOEXEC
-# define SOCK_CLOEXEC O_CLOEXEC
-# endif
-# ifndef SOCK_NONBLOCK
-# define SOCK_NONBLOCK O_NONBLOCK
-# endif
-# ifndef MSG_CMSG_CLOEXEC
-# define MSG_CMSG_CLOEXEC 0x40000000
-# endif
-
QT_BEGIN_NAMESPACE
namespace QtLibcSupplement {
- Q_CORE_EXPORT int accept4(int, sockaddr *, QT_SOCKLEN_T *, int flags);
- Q_CORE_EXPORT int dup3(int oldfd, int newfd, int flags);
- Q_CORE_EXPORT int pipe2(int pipes[], int flags);
+ inline int accept4(int, sockaddr *, QT_SOCKLEN_T *, int)
+ { errno = ENOSYS; return -1; }
+ inline int dup3(int, int, int)
+ { errno = ENOSYS; return -1; }
+ inline int pipe2(int [], int )
+ { errno = ENOSYS; return -1; }
}
QT_END_NAMESPACE
using namespace QT_PREPEND_NAMESPACE(QtLibcSupplement);
@@ -190,7 +174,7 @@ static inline int qt_safe_pipe(int pipefd[2], int flags = 0)
#endif
register int ret;
-#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC
+#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(O_CLOEXEC)
// use pipe2
flags |= O_CLOEXEC;
ret = ::pipe2(pipefd, flags); // pipe2 is Linux-specific and is documented not to return EINTR
@@ -246,7 +230,7 @@ static inline int qt_safe_dup2(int oldfd, int newfd, int flags = FD_CLOEXEC)
Q_ASSERT(flags == FD_CLOEXEC || flags == 0);
register int ret;
-#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC
+#if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(O_CLOEXEC)
// use dup3
if (flags & FD_CLOEXEC) {
EINTR_LOOP(ret, ::dup3(oldfd, newfd, O_CLOEXEC));
diff --git a/src/network/socket/qnet_unix_p.h b/src/network/socket/qnet_unix_p.h
index f38c2fc..040b3ec 100644
--- a/src/network/socket/qnet_unix_p.h
+++ b/src/network/socket/qnet_unix_p.h
@@ -85,7 +85,7 @@ static inline int qt_safe_socket(int domain, int type, int protocol, int flags =
Q_ASSERT((flags & ~O_NONBLOCK) == 0);
register int fd;
-#ifdef SOCK_CLOEXEC
+#if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
int newtype = type | SOCK_CLOEXEC;
if (flags & O_NONBLOCK)
newtype |= SOCK_NONBLOCK;