summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess_unix.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2017-08-17 09:16:16 +0300
committerEdward Welbourne <edward.welbourne@qt.io>2017-08-18 07:25:52 +0000
commit362466c7d2e12c4587d5de1eb51cd537be9f7e2b (patch)
tree28a1cf1e209d32e6d69030a05a1069d59e26c449 /src/corelib/io/qprocess_unix.cpp
parent1cd91a0ee58a653e7543dc01988d92adc89d3116 (diff)
QProcess/Unix: fix possible race condition inside waitForXXX() loops
Calling QCoreApplication::processEvents() from a slot connected to the readyRead() signal might cause desynchronization in the waitForXXX() loop, if the process has been finished during the event processing. This results in unnecessary timeouts and causes waitForFinished() to fail unexpectedly. So, a proposed solution is to check the state on each iteration of the loop, as Windows implementation does. Given issue is tested by tst_QProcess::processEventsInAReadyReadSlot() which was unstable in CI. Task-number: QTBUG-62584 Change-Id: I7438cf67b0163bbf49314008a9dc660c0977fb7b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qprocess_unix.cpp')
-rw-r--r--src/corelib/io/qprocess_unix.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 6b7f187fee..318c633017 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -792,6 +792,10 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
if (qt_pollfd_check(poller.stdinPipe(), POLLOUT))
_q_canWrite();
+ // Signals triggered by I/O may have stopped this process:
+ if (processState == QProcess::NotRunning)
+ return false;
+
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied())
return false;
@@ -838,6 +842,10 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
if (qt_pollfd_check(poller.stderrPipe(), POLLIN))
_q_canReadStandardError();
+ // Signals triggered by I/O may have stopped this process:
+ if (processState == QProcess::NotRunning)
+ return false;
+
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied())
return false;
@@ -883,6 +891,10 @@ bool QProcessPrivate::waitForFinished(int msecs)
if (qt_pollfd_check(poller.stderrPipe(), POLLIN))
_q_canReadStandardError();
+ // Signals triggered by I/O may have stopped this process:
+ if (processState == QProcess::NotRunning)
+ return true;
+
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied())
return true;