summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-02-11 13:14:05 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-12 06:11:04 +0100
commit691212d9e492b12590d5b7f4e2b24921911d4b17 (patch)
tree7f2026bb0eb5961927b72e8e92324152527e7660
parent6ce439a6393cd857f3eb9ffeba0ad6594cf4ae63 (diff)
downloadqtserialport-691212d9e492b12590d5b7f4e2b24921911d4b17.tar.gz
Open file descriptors thread-safely on Unix and don't leak them
::open directly is not thread-safe. You need to pass O_CLOEXEC if the OS supports it. That's the only thread-safe way to open files. qt_safe_open does that for you. This patch also implicitly makes all serial devices be opened with CLOEXEC on all systems, which prevents the file descriptors from leaking to child processes. Change-Id: I83a2657fa8d9ccca1b42182bcd83416091066045 Reviewed-by: Laszlo Papp <lpapp@kde.org>
-rw-r--r--src/serialport/qserialport_unix.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 844ba13..a788b4d 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -59,6 +59,8 @@
#include <QtCore/qsocketnotifier.h>
#include <QtCore/qmap.h>
+#include <private/qcore_unix_p.h>
+
QT_BEGIN_NAMESPACE
QString serialPortLockFilePath(const QString &portName)
@@ -213,7 +215,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
break;
}
- descriptor = ::open(systemLocation.toLocal8Bit().constData(), flags);
+ descriptor = qt_safe_open(systemLocation.toLocal8Bit().constData(), flags);
if (descriptor == -1) {
q->setError(decodeSystemError());