From 28ee554b37be39c03c231e7b857f71163dc6ea73 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 30 Apr 2013 15:31:46 +0200 Subject: QProcess/Win: drain output pipes on process finish If a process dies before all output is read into the internal buffer of QProcess, we might lose data. Therefore we must drain the output pipes like we already do in the synchronous wait functions. Task-number: QTBUG-30843 Change-Id: I8bbc5265275c9ebd33218ba600267ae87d93ed61 Reviewed-by: Oswald Buddenhagen Reviewed-by: Friedemann Kleint --- src/corelib/io/qprocess.cpp | 1 + src/corelib/io/qprocess_p.h | 1 + src/corelib/io/qprocess_win.cpp | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 59b6db7c79..3de1345585 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1006,6 +1006,7 @@ bool QProcessPrivate::_q_processDied() return false; #endif #ifdef Q_OS_WIN + drainOutputPipes(); if (processFinishedNotifier) processFinishedNotifier->setEnabled(false); #endif diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index f658e54d4b..bd6943c8d0 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -317,6 +317,7 @@ public: bool waitForDeadChild(); #endif #ifdef Q_OS_WIN + bool drainOutputPipes(); void flushPipeWriter(); qint64 pipeWriterBytesToWrite() const; #endif diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 0f36c3adbf..7776852277 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -625,21 +625,21 @@ bool QProcessPrivate::waitForStarted(int) return false; } -static bool drainOutputPipes(QProcessPrivate *d) +bool QProcessPrivate::drainOutputPipes() { - if (!d->stdoutReader && !d->stderrReader) + if (!stdoutReader && !stderrReader) return false; bool readyReadEmitted = false; forever { bool readOperationActive = false; - if (d->stdoutReader) { - readyReadEmitted |= d->stdoutReader->waitForReadyRead(0); - readOperationActive = d->stdoutReader->isReadOperationActive(); + if (stdoutReader) { + readyReadEmitted |= stdoutReader->waitForReadyRead(0); + readOperationActive = stdoutReader->isReadOperationActive(); } - if (d->stderrReader) { - readyReadEmitted |= d->stderrReader->waitForReadyRead(0); - readOperationActive |= d->stderrReader->isReadOperationActive(); + if (stderrReader) { + readyReadEmitted |= stderrReader->waitForReadyRead(0); + readOperationActive |= stderrReader->isReadOperationActive(); } if (!readOperationActive) break; @@ -669,7 +669,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs) if (!pid) return false; if (WaitForSingleObject(pid->hProcess, 0) == WAIT_OBJECT_0) { - bool readyReadEmitted = drainOutputPipes(this); + bool readyReadEmitted = drainOutputPipes(); _q_processDied(); return readyReadEmitted; } @@ -772,12 +772,12 @@ bool QProcessPrivate::waitForFinished(int msecs) timer.resetIncrements(); if (!pid) { - drainOutputPipes(this); + drainOutputPipes(); return true; } if (WaitForSingleObject(pid->hProcess, timer.nextSleepTime()) == WAIT_OBJECT_0) { - drainOutputPipes(this); + drainOutputPipes(); _q_processDied(); return true; } -- cgit v1.2.3