forked from qt-creator/qt-creator
remove pointless process state checking
this partially reverts ddefe062c7
- contrary to what that commit's
message suggests, the process state doesn't just change out of the blue,
making waitForFinished() return false. that requires the process being
reaped, which may happen only if the event loop runs or one of the
I/O-related waitFor*() functions is called on that process.
note that the first condition in SynchronousProcess::stopProcess() was
actually bogus, as it makes obviously no sense whatsoever to insist that
the process is still running after waitForFinished() returned success.
qtpromaker was also plain broken - it would always terminate prematurely
due to thinking that the sub-process failed.
Change-Id: I44f332a6784ccc7e732ee868e38218f746141129
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -522,20 +522,17 @@ SynchronousProcessResponse SynchronousProcess::runBlocking(const CommandLine &cm
|
||||
|
||||
d->m_binary = cmd.executable();
|
||||
d->m_process.start(cmd.executable().toString(), cmd.splitArguments(), QIODevice::ReadOnly);
|
||||
if (!d->m_process.waitForStarted(d->m_maxHangTimerCount * 1000)
|
||||
&& d->m_process.state() == QProcess::NotRunning) {
|
||||
if (!d->m_process.waitForStarted(d->m_maxHangTimerCount * 1000)) {
|
||||
d->m_result.result = SynchronousProcessResponse::StartFailed;
|
||||
return d->m_result;
|
||||
}
|
||||
d->m_process.closeWriteChannel();
|
||||
if (!d->m_process.waitForFinished(d->m_maxHangTimerCount * 1000)) {
|
||||
if (d->m_process.state() == QProcess::Running) {
|
||||
d->m_result.result = SynchronousProcessResponse::Hang;
|
||||
d->m_process.terminate();
|
||||
if (!d->m_process.waitForFinished(1000) && d->m_process.state() == QProcess::Running) {
|
||||
d->m_process.kill();
|
||||
d->m_process.waitForFinished(1000);
|
||||
}
|
||||
d->m_result.result = SynchronousProcessResponse::Hang;
|
||||
d->m_process.terminate();
|
||||
if (!d->m_process.waitForFinished(1000)) {
|
||||
d->m_process.kill();
|
||||
d->m_process.waitForFinished(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,10 +701,10 @@ bool SynchronousProcess::stopProcess(QProcess &p)
|
||||
if (p.state() == QProcess::NotRunning)
|
||||
return true;
|
||||
p.terminate();
|
||||
if (p.waitForFinished(300) && p.state() == QProcess::Running)
|
||||
if (p.waitForFinished(300))
|
||||
return true;
|
||||
p.kill();
|
||||
return p.waitForFinished(300) || p.state() == QProcess::NotRunning;
|
||||
return p.waitForFinished(300);
|
||||
}
|
||||
|
||||
// Path utilities
|
||||
|
@@ -415,7 +415,7 @@ static QString findQtInstallPath(const FilePath &qmakePath)
|
||||
return QString();
|
||||
}
|
||||
proc.closeWriteChannel();
|
||||
if (!proc.waitForFinished() && proc.state() == QProcess::Running) {
|
||||
if (!proc.waitForFinished()) {
|
||||
SynchronousProcess::stopProcess(proc);
|
||||
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(qmakePath.toString()));
|
||||
return QString();
|
||||
|
@@ -88,7 +88,7 @@ Utils::Port IosSimulator::nextPort() const
|
||||
if (!portVerifier.waitForStarted())
|
||||
break;
|
||||
portVerifier.closeWriteChannel();
|
||||
if (!portVerifier.waitForFinished() && portVerifier.state() == QProcess::Running)
|
||||
if (!portVerifier.waitForFinished())
|
||||
break;
|
||||
if (portVerifier.exitStatus() != QProcess::NormalExit
|
||||
|| portVerifier.exitCode() != 0)
|
||||
|
@@ -194,7 +194,7 @@ void ApplicationLauncherPrivate::stop()
|
||||
localProcessDone(0, QProcess::CrashExit);
|
||||
} else {
|
||||
m_guiProcess.terminate();
|
||||
if (!m_guiProcess.waitForFinished(1000) && m_guiProcess.state() == QProcess::Running) { // This is blocking, so be fast.
|
||||
if (!m_guiProcess.waitForFinished(1000)) { // This is blocking, so be fast.
|
||||
m_guiProcess.kill();
|
||||
m_guiProcess.waitForFinished();
|
||||
}
|
||||
|
@@ -429,7 +429,7 @@ void ProcessExtraCompiler::runInThread(
|
||||
if (!isCanceled) {
|
||||
handleProcessStarted(&process, sourceContents);
|
||||
forever {
|
||||
bool done = process.waitForFinished(200) || process.state() == QProcess::NotRunning;
|
||||
bool done = process.waitForFinished(200);
|
||||
isCanceled = futureInterface.isCanceled();
|
||||
if (done || isCanceled)
|
||||
break;
|
||||
|
@@ -119,7 +119,7 @@ Utils::EnvironmentItems QnxUtils::qnxEnvironmentFromEnvFile(const QString &fileN
|
||||
|
||||
// waiting for finish
|
||||
QApplication::setOverrideCursor(Qt::BusyCursor);
|
||||
bool waitResult = process.waitForFinished(10000) || process.state() == QProcess::NotRunning;
|
||||
bool waitResult = process.waitForFinished(10000);
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (!waitResult) {
|
||||
Utils::SynchronousProcess::stopProcess(process);
|
||||
|
@@ -1743,7 +1743,7 @@ static QByteArray runQmakeQuery(const FilePath &binary, const Environment &env,
|
||||
*error = QCoreApplication::translate("QtVersion", "Cannot start \"%1\": %2").arg(binary.toUserOutput()).arg(process.errorString());
|
||||
return QByteArray();
|
||||
}
|
||||
if (!process.waitForFinished(timeOutMS) && process.state() == QProcess::Running) {
|
||||
if (!process.waitForFinished(timeOutMS)) {
|
||||
SynchronousProcess::stopProcess(process);
|
||||
*error = QCoreApplication::translate("QtVersion", "Timeout running \"%1\" (%2 ms).").arg(binary.toUserOutput()).arg(timeOutMS);
|
||||
return QByteArray();
|
||||
|
@@ -125,7 +125,7 @@ static FormatTask format(FormatTask task)
|
||||
}
|
||||
process.write(task.sourceData.toUtf8());
|
||||
process.closeWriteChannel();
|
||||
if (!process.waitForFinished(5000) && process.state() == QProcess::Running) {
|
||||
if (!process.waitForFinished(5000)) {
|
||||
process.kill();
|
||||
task.error = QString(QT_TRANSLATE_NOOP("TextEditor",
|
||||
"Cannot call %1 or some other error occurred. Timeout "
|
||||
|
@@ -57,7 +57,7 @@ void executeCommand(const QString &command, const QStringList &arguments, const
|
||||
<< Qt::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (!process.waitForFinished() && process.state() == QProcess::Running) {
|
||||
if (!process.waitForFinished()) {
|
||||
if (!verbose)
|
||||
out << process.readAll() << Qt::endl;
|
||||
out << QString::fromLatin1("Error: Process \"%1\" did not finish within timeout.").arg(fullCommand)
|
||||
|
@@ -333,7 +333,7 @@ bool startCreatorAsDebugger(bool asClient, QString *errorMessage)
|
||||
// Short execution time: indicates that -client was passed on attach to
|
||||
// another running instance of Qt Creator. Keep alive as long as user
|
||||
// does not close the process. If that fails, try to launch 2nd instance.
|
||||
const bool waitResult = p.waitForFinished(-1) || p.state() == QProcess::NotRunning;
|
||||
const bool waitResult = p.waitForFinished(-1);
|
||||
const bool ranAsClient = asClient && (executionTime.elapsed() < 10000);
|
||||
if (waitResult && p.exitStatus() == QProcess::NormalExit && ranAsClient) {
|
||||
if (p.exitCode() == 0) {
|
||||
|
@@ -206,7 +206,7 @@ void Project::handleBinary(const QString &item)
|
||||
qDebug() << "COULD NOT START";
|
||||
return;
|
||||
}
|
||||
if (!proc.waitForFinished() || proc.state() == QProcess::NotRunning) {
|
||||
if (!proc.waitForFinished()) {
|
||||
qDebug() << "COULD NOT FINISH";
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user