diff options
Diffstat (limited to 'src/gui/embedded/qunixsocket.cpp')
-rw-r--r-- | src/gui/embedded/qunixsocket.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/gui/embedded/qunixsocket.cpp b/src/gui/embedded/qunixsocket.cpp index 9db361a..8d7b67e 100644 --- a/src/gui/embedded/qunixsocket.cpp +++ b/src/gui/embedded/qunixsocket.cpp @@ -46,6 +46,7 @@ #include <QtCore/qsocketnotifier.h> #include <QtCore/qqueue.h> #include <QtCore/qdatetime.h> +#include "private/qcore_unix_p.h" // overrides QT_OPEN #ifdef QUNIXSOCKET_DEBUG #include <QtCore/qdebug.h> @@ -131,11 +132,11 @@ struct QUnixSocketRightsPrivate : public QSharedData #ifdef QUNIXSOCKET_DEBUG int closerv = #endif - ::close(fd); + QT_CLOSE(fd); #ifdef QUNIXSOCKET_DEBUG if(0 != closerv) { qDebug() << "QUnixSocketRightsPrivate: Unable to close managed" - " file descriptor (" << ::strerror(errno) << ")"; + " file descriptor (" << ::strerror(errno) << ')'; } #endif } @@ -162,11 +163,11 @@ QUnixSocketRights::QUnixSocketRights(int fd) if(-1 == fd) { d->fd = -1; } else { - d->fd = ::dup(fd); + d->fd = qt_safe_dup(fd); #ifdef QUNIXSOCKET_DEBUG if(-1 == d->fd) { qDebug() << "QUnixSocketRights: Unable to duplicate fd " - << fd << " (" << ::strerror(errno) << ")"; + << fd << " (" << ::strerror(errno) << ')'; } #endif } @@ -232,12 +233,12 @@ int QUnixSocketRights::dupFd() const { if(-1 == d->fd) return -1; - int rv = ::dup(d->fd); + int rv = qt_safe_dup(d->fd); #ifdef QUNIXSOCKET_DEBUG if(-1 == rv) qDebug() << "QUnixSocketRights: Unable to duplicate managed file " - "descriptor (" << ::strerror(errno) << ")"; + "descriptor (" << ::strerror(errno) << ')'; #endif return rv; @@ -825,7 +826,7 @@ public: int numFds = (h->cmsg_len - CMSG_LEN(0)) / sizeof(int); for(int ii = 0; ii < numFds; ++ii) - ::close(fds[ii]); + QT_CLOSE(fds[ii]); } h = (::cmsghdr *)CMSG_NXTHDR(&(message), h); @@ -927,7 +928,7 @@ bool QUnixSocket::connect(const QByteArray & path) int crv; #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Connect requested to '" - << path << "'"; + << path << '\''; #endif abort(); // Reset any existing connection @@ -949,7 +950,7 @@ bool QUnixSocket::connect(const QByteArray & path) if(-1 == d->fd) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to create socket (" - << strerror(errno) << ")"; + << strerror(errno) << ')'; #endif d->error = ResourceError; goto connect_error; @@ -962,7 +963,7 @@ bool QUnixSocket::connect(const QByteArray & path) if(-1 == crv) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to configure socket (" - << ::strerror(errno) << ")"; + << ::strerror(errno) << ')'; #endif d->error = ResourceError; @@ -981,7 +982,7 @@ bool QUnixSocket::connect(const QByteArray & path) if(-1 == crv) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to connect (" - << ::strerror(errno) << ")"; + << ::strerror(errno) << ')'; #endif if(ECONNREFUSED == errno) d->error = ConnectionRefused; @@ -1017,11 +1018,11 @@ connect_error: // Cleanup failed connection #ifdef QUNIXSOCKET_DEBUG int closerv = #endif - ::close(d->fd); + QT_CLOSE(d->fd); #ifdef QUNIXSOCKET_DEBUG if(0 != closerv) { qDebug() << "QUnixSocket: Unable to close file descriptor after " - "failed connect (" << ::strerror(errno) << ")"; + "failed connect (" << ::strerror(errno) << ')'; } #endif } @@ -1065,7 +1066,7 @@ bool QUnixSocket::setSocketDescriptor(int socketDescriptor) if(-1 == crv) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to configure client provided socket (" - << ::strerror(errno) << ")"; + << ::strerror(errno) << ')'; #endif d->error = ResourceError; @@ -1136,7 +1137,7 @@ void QUnixSocket::abort() #ifdef QUNIXSOCKET_DEBUG if(0 != closerv) { qDebug() << "QUnixSocket: Unable to close socket during abort (" - << strerror(errno) << ")"; + << strerror(errno) << ')'; } #endif @@ -1686,11 +1687,11 @@ qint64 QUnixSocketPrivate::writeActivated() } #ifdef QUNIXSOCKET_DEBUG - qDebug() << "QUnixSocket: Transmitting message (length" << m.d->size() << ")"; + qDebug() << "QUnixSocket: Transmitting message (length" << m.d->size() << ')'; #endif ::ssize_t s = ::sendmsg(fd, &sendmessage, MSG_DONTWAIT | MSG_NOSIGNAL); #ifdef QUNIXSOCKET_DEBUG - qDebug() << "QUnixSocket: Transmitted message (" << s << ")"; + qDebug() << "QUnixSocket: Transmitted message (" << s << ')'; #endif if(-1 == s) { @@ -1699,13 +1700,13 @@ qint64 QUnixSocketPrivate::writeActivated() } else if(EPIPE == errno) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Remote side disconnected during transmit " - "(" << ::strerror(errno) << ")"; + "(" << ::strerror(errno) << ')'; #endif me->abort(); } else { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to transmit data (" - << ::strerror(errno) << ")"; + << ::strerror(errno) << ')'; #endif error = (QUnixSocket::SocketError)(QUnixSocket::WriteFailure | CausedAbort); @@ -1762,14 +1763,19 @@ void QUnixSocketPrivate::readActivated() message.msg_controllen = ancillaryBufferCapacity(); message.msg_control = ancillaryBuffer; - int recvrv = ::recvmsg(fd, &message, 0); + int flags = 0; +#ifdef MSG_CMSG_CLOEXEC + flags = MSG_CMSG_CLOEXEC; +#endif + + int recvrv = ::recvmsg(fd, &message, flags); #ifdef QUNIXSOCKET_DEBUG - qDebug() << "QUnixSocket: Received message (" << recvrv << ")"; + qDebug() << "QUnixSocket: Received message (" << recvrv << ')'; #endif if(-1 == recvrv) { #ifdef QUNIXSOCKET_DEBUG qDebug() << "QUnixSocket: Unable to receive data (" - << ::strerror(errno) << ")"; + << ::strerror(errno) << ')'; #endif error = (QUnixSocket::SocketError)(QUnixSocket::ReadFailure | CausedAbort); |