QProcess: simplify the logic around _q_processDied()

Both on Unix and Windows, _q_processDied() unconditionally releases all
resources associated with the terminated child process, resets QProcess
to the initial state, and emits finished() signal. Thus, we can omit
reporting success, which also eliminates the related checks from
callers.

Change-Id: I40e32d1a9ccc8d488be6badba934355d734a8abd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
Alex Trotsenko 2020-12-02 17:22:10 +02:00
parent 895940a425
commit ec02de374d
4 changed files with 15 additions and 18 deletions

View File

@ -1057,15 +1057,14 @@ bool QProcessPrivate::_q_canWrite()
/*! /*!
\internal \internal
*/ */
bool QProcessPrivate::_q_processDied() void QProcessPrivate::_q_processDied()
{ {
Q_Q(QProcess); Q_Q(QProcess);
#if defined QPROCESS_DEBUG #if defined QPROCESS_DEBUG
qDebug("QProcessPrivate::_q_processDied()"); qDebug("QProcessPrivate::_q_processDied()");
#endif #endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
if (!waitForDeadChild()) waitForDeadChild();
return false;
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (processFinishedNotifier) if (processFinishedNotifier)
@ -1078,7 +1077,7 @@ bool QProcessPrivate::_q_processDied()
// give it a chance to emit started() or errorOccurred(FailedToStart). // give it a chance to emit started() or errorOccurred(FailedToStart).
if (processState == QProcess::Starting) { if (processState == QProcess::Starting) {
if (!_q_startupNotification()) if (!_q_startupNotification())
return true; return;
} }
if (dying) { if (dying) {
@ -1086,7 +1085,7 @@ bool QProcessPrivate::_q_processDied()
// reentering this slot recursively by calling waitForFinished() // reentering this slot recursively by calling waitForFinished()
// or opening a dialog inside slots connected to the readyRead // or opening a dialog inside slots connected to the readyRead
// signals emitted below. // signals emitted below.
return true; return;
} }
dying = true; dying = true;
@ -1119,7 +1118,6 @@ bool QProcessPrivate::_q_processDied()
#if defined QPROCESS_DEBUG #if defined QPROCESS_DEBUG
qDebug("QProcessPrivate::_q_processDied() process is dead"); qDebug("QProcessPrivate::_q_processDied() process is dead");
#endif #endif
return true;
} }
/*! /*!

View File

@ -283,7 +283,7 @@ private:
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError()) Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError())
Q_PRIVATE_SLOT(d_func(), bool _q_canWrite()) Q_PRIVATE_SLOT(d_func(), bool _q_canWrite())
Q_PRIVATE_SLOT(d_func(), bool _q_startupNotification()) Q_PRIVATE_SLOT(d_func(), bool _q_startupNotification())
Q_PRIVATE_SLOT(d_func(), bool _q_processDied()) Q_PRIVATE_SLOT(d_func(), void _q_processDied())
friend class QProcessManager; friend class QProcessManager;
}; };

View File

@ -295,7 +295,7 @@ public:
bool _q_canReadStandardError(); bool _q_canReadStandardError();
bool _q_canWrite(); bool _q_canWrite();
bool _q_startupNotification(); bool _q_startupNotification();
bool _q_processDied(); void _q_processDied();
QProcess::ProcessChannelMode processChannelMode = QProcess::SeparateChannels; QProcess::ProcessChannelMode processChannelMode = QProcess::SeparateChannels;
QProcess::InputChannelMode inputChannelMode = QProcess::ManagedInputChannel; QProcess::InputChannelMode inputChannelMode = QProcess::ManagedInputChannel;
@ -354,7 +354,7 @@ public:
void killProcess(); void killProcess();
void findExitCode(); void findExitCode();
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
bool waitForDeadChild(); void waitForDeadChild();
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
bool callCreateProcess(QProcess::CreateProcessArguments *cpargs); bool callCreateProcess(QProcess::CreateProcessArguments *cpargs);

View File

@ -768,8 +768,8 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
return false; return false;
if (qt_pollfd_check(poller.forkfd(), POLLIN)) { if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied()) _q_processDied();
return false; return false;
} }
} }
return false; return false;
@ -818,8 +818,8 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
return false; return false;
if (qt_pollfd_check(poller.forkfd(), POLLIN)) { if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied()) _q_processDied();
return false; return false;
} }
} }
@ -867,8 +867,8 @@ bool QProcessPrivate::waitForFinished(int msecs)
return true; return true;
if (qt_pollfd_check(poller.forkfd(), POLLIN)) { if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
if (_q_processDied()) _q_processDied();
return true; return true;
} }
} }
return false; return false;
@ -878,10 +878,10 @@ void QProcessPrivate::findExitCode()
{ {
} }
bool QProcessPrivate::waitForDeadChild() void QProcessPrivate::waitForDeadChild()
{ {
if (forkfd == -1) if (forkfd == -1)
return true; // child has already exited return; // child has already been reaped
// read the process information from our fd // read the process information from our fd
forkfd_info info; forkfd_info info;
@ -901,7 +901,6 @@ bool QProcessPrivate::waitForDeadChild()
qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode" qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode"
<< exitCode << ", crashed?" << crashed; << exitCode << ", crashed?" << crashed;
#endif #endif
return true;
} }
bool QProcessPrivate::startDetached(qint64 *pid) bool QProcessPrivate::startDetached(qint64 *pid)