summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-04-10 17:29:26 +0200
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-04-10 16:01:19 +0000
commitbd62a82530c20ceb58db78c556ec40e113f3358f (patch)
treecd6e1af6f06919caa41728c0353aadbadd34f82a
parentce29b1c409e1a4857bdaa3645b5ce5676506d730 (diff)
make detection of the death of a child process more robust
The detection of the death of a child process entirely relied on the IO completion port returning a failure for the read on stdout or stderr. If no such failure happened, Process wouldn't detect the death of the process. Added a QWinEventNotifier that listens on the process handle to make the detection more robust. Change-Id: Ib5ae34950a9aa43edc5dc9109ff199687d3fd672 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r--src/jomlib/process.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/jomlib/process.cpp b/src/jomlib/process.cpp
index 25f461c..f178de2 100644
--- a/src/jomlib/process.cpp
+++ b/src/jomlib/process.cpp
@@ -33,6 +33,7 @@
#include <QMetaType>
#include <QMutex>
#include <QTimer>
+#include <QWinEventNotifier>
#include <qt_windows.h>
#include <errno.h>
@@ -134,6 +135,7 @@ public:
OutputChannel stderrChannel;
QMutex bufferedOutputModeSwitchMutex;
DWORD exitCode;
+ QWinEventNotifier deathNotifier;
};
Process::Process(QObject *parent)
@@ -152,6 +154,8 @@ Process::Process(QObject *parent)
qRegisterMetaType<ProcessState>("Process::ProcessState");
runtime()->start();
}
+ connect(&d->deathNotifier, &QWinEventNotifier::activated,
+ this, &Process::tryToRetrieveExitCode);
}
Process::~Process()
@@ -403,6 +407,8 @@ void Process::start(const QString &commandLine)
safelyCloseHandle(d->stdoutPipe.hWrite);
safelyCloseHandle(d->stderrPipe.hWrite);
+ d->deathNotifier.setHandle(pi.hProcess);
+ d->deathNotifier.setEnabled(true);
d->hProcess = pi.hProcess;
d->hProcessThread = pi.hThread;
m_state = Running;
@@ -425,6 +431,7 @@ void Process::onProcessFinished()
if (m_state != Running)
return;
+ d->deathNotifier.setEnabled(false);
iocp()->unregisterObserver(&d->stdoutChannel);
iocp()->unregisterObserver(&d->stderrChannel);
safelyCloseHandle(d->stdoutPipe.hRead);