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:
parent
895940a425
commit
ec02de374d
@ -1057,15 +1057,14 @@ bool QProcessPrivate::_q_canWrite()
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
bool QProcessPrivate::_q_processDied()
|
||||
void QProcessPrivate::_q_processDied()
|
||||
{
|
||||
Q_Q(QProcess);
|
||||
#if defined QPROCESS_DEBUG
|
||||
qDebug("QProcessPrivate::_q_processDied()");
|
||||
#endif
|
||||
#ifdef Q_OS_UNIX
|
||||
if (!waitForDeadChild())
|
||||
return false;
|
||||
waitForDeadChild();
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
if (processFinishedNotifier)
|
||||
@ -1078,7 +1077,7 @@ bool QProcessPrivate::_q_processDied()
|
||||
// give it a chance to emit started() or errorOccurred(FailedToStart).
|
||||
if (processState == QProcess::Starting) {
|
||||
if (!_q_startupNotification())
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dying) {
|
||||
@ -1086,7 +1085,7 @@ bool QProcessPrivate::_q_processDied()
|
||||
// reentering this slot recursively by calling waitForFinished()
|
||||
// or opening a dialog inside slots connected to the readyRead
|
||||
// signals emitted below.
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
dying = true;
|
||||
|
||||
@ -1119,7 +1118,6 @@ bool QProcessPrivate::_q_processDied()
|
||||
#if defined QPROCESS_DEBUG
|
||||
qDebug("QProcessPrivate::_q_processDied() process is dead");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -283,7 +283,7 @@ private:
|
||||
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError())
|
||||
Q_PRIVATE_SLOT(d_func(), bool _q_canWrite())
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -295,7 +295,7 @@ public:
|
||||
bool _q_canReadStandardError();
|
||||
bool _q_canWrite();
|
||||
bool _q_startupNotification();
|
||||
bool _q_processDied();
|
||||
void _q_processDied();
|
||||
|
||||
QProcess::ProcessChannelMode processChannelMode = QProcess::SeparateChannels;
|
||||
QProcess::InputChannelMode inputChannelMode = QProcess::ManagedInputChannel;
|
||||
@ -354,7 +354,7 @@ public:
|
||||
void killProcess();
|
||||
void findExitCode();
|
||||
#ifdef Q_OS_UNIX
|
||||
bool waitForDeadChild();
|
||||
void waitForDeadChild();
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
bool callCreateProcess(QProcess::CreateProcessArguments *cpargs);
|
||||
|
@ -768,8 +768,8 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
|
||||
return false;
|
||||
|
||||
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
|
||||
if (_q_processDied())
|
||||
return false;
|
||||
_q_processDied();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -818,8 +818,8 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
|
||||
return false;
|
||||
|
||||
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
|
||||
if (_q_processDied())
|
||||
return false;
|
||||
_q_processDied();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -867,8 +867,8 @@ bool QProcessPrivate::waitForFinished(int msecs)
|
||||
return true;
|
||||
|
||||
if (qt_pollfd_check(poller.forkfd(), POLLIN)) {
|
||||
if (_q_processDied())
|
||||
return true;
|
||||
_q_processDied();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -878,10 +878,10 @@ void QProcessPrivate::findExitCode()
|
||||
{
|
||||
}
|
||||
|
||||
bool QProcessPrivate::waitForDeadChild()
|
||||
void QProcessPrivate::waitForDeadChild()
|
||||
{
|
||||
if (forkfd == -1)
|
||||
return true; // child has already exited
|
||||
return; // child has already been reaped
|
||||
|
||||
// read the process information from our fd
|
||||
forkfd_info info;
|
||||
@ -901,7 +901,6 @@ bool QProcessPrivate::waitForDeadChild()
|
||||
qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode"
|
||||
<< exitCode << ", crashed?" << crashed;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QProcessPrivate::startDetached(qint64 *pid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user