From 5d3823ac4727fb426915b468a031346e5f9ab929 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 26 May 2016 12:12:01 +0200 Subject: Use SynchronousProcess::runBlocking Use SynchronousProcess::runBlocking in favor of SychronousProcess::run. This avoid nested event loops which can produce really strange crashes if not use carefully. This patch only converts those processes that have a timeout of less than 5 seconds or use the default timeout. Change-Id: I9de8899dcc946af7049ea357a91972996c0256a1 Reviewed-by: Vikas Pachdha Reviewed-by: Tobias Hunger --- src/libs/utils/buildablehelperlibrary.cpp | 4 ++-- src/libs/utils/pathchooser.cpp | 2 +- src/plugins/android/androidconfigurations.cpp | 13 +++++++------ src/plugins/android/androidrunner.cpp | 2 +- .../beautifier/artisticstyle/artisticstylesettings.cpp | 4 ++-- src/plugins/beautifier/beautifierplugin.cpp | 2 +- src/plugins/beautifier/uncrustify/uncrustifysettings.cpp | 2 +- src/plugins/cmakeprojectmanager/cmaketool.cpp | 2 +- src/plugins/debugger/debuggeritem.cpp | 2 +- src/plugins/debugger/debuggeritemmanager.cpp | 4 ++-- src/plugins/debugger/gdb/coregdbadapter.cpp | 2 +- src/plugins/projectexplorer/abstractmsvctoolchain.cpp | 2 +- src/plugins/projectexplorer/msvctoolchain.cpp | 2 +- .../texteditor/generichighlighter/highlightersettings.cpp | 2 +- 14 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/libs/utils/buildablehelperlibrary.cpp b/src/libs/utils/buildablehelperlibrary.cpp index a57c829a22..357bc2fea2 100644 --- a/src/libs/utils/buildablehelperlibrary.cpp +++ b/src/libs/utils/buildablehelperlibrary.cpp @@ -43,7 +43,7 @@ QString BuildableHelperLibrary::qtChooserToQmakePath(const QString &path) const QString toolDir = QLatin1String("QTTOOLDIR=\""); SynchronousProcess proc; proc.setTimeoutS(1); - SynchronousProcessResponse response = proc.run(path, QStringList(QLatin1String("-print-env"))); + SynchronousProcessResponse response = proc.runBlocking(path, QStringList(QLatin1String("-print-env"))); if (response.result != SynchronousProcessResponse::Finished) return QString(); const QString output = response.stdOut; @@ -104,7 +104,7 @@ QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath) SynchronousProcess qmake; qmake.setTimeoutS(5); - SynchronousProcessResponse response = qmake.run(qmakePath, QStringList(QLatin1String("--version"))); + SynchronousProcessResponse response = qmake.runBlocking(qmakePath, QStringList(QLatin1String("--version"))); if (response.result != SynchronousProcessResponse::Finished) { qWarning() << response.exitMessage(qmakePath, 5); return QString(); diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 3ee3233936..e14b67d68c 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -131,7 +131,7 @@ QString BinaryVersionToolTipEventFilter::toolVersion(const QString &binary, cons return QString(); SynchronousProcess proc; proc.setTimeoutS(1); - SynchronousProcessResponse response = proc.run(binary, arguments); + SynchronousProcessResponse response = proc.runBlocking(binary, arguments); if (response.result != SynchronousProcessResponse::Finished) return QString(); return response.allOutput(); diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index 48433a07f5..032af374d3 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -385,7 +385,8 @@ void AndroidConfig::updateAvailableSdkPlatforms() const SynchronousProcess proc; proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment()); SynchronousProcessResponse response - = proc.run(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs + = proc.runBlocking(androidToolPath().toString(), + QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs if (response.result != SynchronousProcessResponse::Finished) return; @@ -673,9 +674,9 @@ bool AndroidConfig::removeAVD(const QString &name) const proc.setTimeoutS(5); proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment()); SynchronousProcessResponse response - = proc.run(androidToolPath().toString(), - QStringList() << QLatin1String("delete") << QLatin1String("avd") - << QLatin1String("-n") << name); + = proc.runBlocking(androidToolPath().toString(), + QStringList() << QLatin1String("delete") << QLatin1String("avd") + << QLatin1String("-n") << name); return response.result == SynchronousProcessResponse::Finished && response.exitCode == 0; } @@ -875,7 +876,7 @@ QString AndroidConfig::getDeviceProperty(const QString &adbToolPath, const QStri SynchronousProcess adbProc; adbProc.setTimeoutS(10); - SynchronousProcessResponse response = adbProc.run(adbToolPath, arguments); + SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath, arguments); if (response.result != SynchronousProcessResponse::Finished) return QString(); @@ -1467,7 +1468,7 @@ void AndroidConfigurations::load() SynchronousProcess proc; proc.setTimeoutS(2); proc.setProcessChannelMode(QProcess::MergedChannels); - SynchronousProcessResponse response = proc.run(javaHomeExec.absoluteFilePath(), QStringList()); + SynchronousProcessResponse response = proc.runBlocking(javaHomeExec.absoluteFilePath(), QStringList()); if (response.result == SynchronousProcessResponse::Finished) { const QString &javaHome = response.allOutput().trimmed(); if (!javaHome.isEmpty() && QFileInfo::exists(javaHome)) diff --git a/src/plugins/android/androidrunner.cpp b/src/plugins/android/androidrunner.cpp index ec29ca4b5b..5d5ed520f4 100644 --- a/src/plugins/android/androidrunner.cpp +++ b/src/plugins/android/androidrunner.cpp @@ -173,7 +173,7 @@ AndroidRunner::AndroidRunner(QObject *parent, Utils::SynchronousProcess psProc; psProc.setTimeoutS(5); Utils::SynchronousProcessResponse response - = psProc.run(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)")); + = psProc.runBlocking(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)")); const QString which = response.allOutput(); m_isBusyBox = which.startsWith("busybox"); diff --git a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp index ea7ea11431..52a546860c 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp @@ -80,7 +80,7 @@ static int updateVersionHelper(const QString &command) { Utils::SynchronousProcess process; Utils::SynchronousProcessResponse response - = process.run(command, QStringList() << QLatin1String("--version")); + = process.runBlocking(command, QStringList() << QLatin1String("--version")); if (response.result != Utils::SynchronousProcessResponse::Finished) return 0; @@ -157,7 +157,7 @@ void ArtisticStyleSettings::createDocumentationFile() const Utils::SynchronousProcess process; process.setTimeoutS(2); Utils::SynchronousProcessResponse response - = process.run(command(), QStringList() << QLatin1String("-h")); + = process.runBlocking(command(), QStringList() << QLatin1String("-h")); if (response.result != Utils::SynchronousProcessResponse::Finished) return; diff --git a/src/plugins/beautifier/beautifierplugin.cpp b/src/plugins/beautifier/beautifierplugin.cpp index 39798ac202..d3f0bbacb9 100644 --- a/src/plugins/beautifier/beautifierplugin.cpp +++ b/src/plugins/beautifier/beautifierplugin.cpp @@ -99,7 +99,7 @@ FormatTask format(FormatTask task) options.replaceInStrings(QLatin1String("%file"), sourceFile.fileName()); Utils::SynchronousProcess process; process.setTimeoutS(5); - Utils::SynchronousProcessResponse response = process.run(executable, options); + Utils::SynchronousProcessResponse response = process.runBlocking(executable, options); if (response.result != Utils::SynchronousProcessResponse::Finished) { task.error = QObject::tr("Failed to format: %1.").arg(response.exitMessage(executable, 5)); return task; diff --git a/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp b/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp index bdbb34c211..804bec3205 100644 --- a/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp +++ b/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp @@ -129,7 +129,7 @@ void UncrustifySettings::createDocumentationFile() const Utils::SynchronousProcess process; process.setTimeoutS(2); Utils::SynchronousProcessResponse response - = process.run(command(), QStringList() << QLatin1String("--show-config")); + = process.runBlocking(command(), QStringList() << QLatin1String("--show-config")); if (response.result != Utils::SynchronousProcessResponse::Finished) return; diff --git a/src/plugins/cmakeprojectmanager/cmaketool.cpp b/src/plugins/cmakeprojectmanager/cmaketool.cpp index 084110ef22..70b362fe34 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketool.cpp @@ -109,7 +109,7 @@ Utils::SynchronousProcessResponse CMakeTool::run(const QString &arg) const cmake.setProcessEnvironment(env.toProcessEnvironment()); cmake.setTimeOutMessageBoxEnabled(false); - Utils::SynchronousProcessResponse response = cmake.run(m_executable.toString(), QStringList() << arg); + Utils::SynchronousProcessResponse response = cmake.runBlocking(m_executable.toString(), QStringList() << arg); m_didAttemptToRun = true; m_didRun = (response.result == Utils::SynchronousProcessResponse::Finished); return response; diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 986a9cb30f..977904e4bf 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -120,7 +120,7 @@ void DebuggerItem::reinitializeFromFile() SynchronousProcess proc; SynchronousProcessResponse response - = proc.run(m_command.toString(), QStringList({ QLatin1String(version) })); + = proc.runBlocking(m_command.toString(), QStringList({ QLatin1String(version) })); if (response.result != SynchronousProcessResponse::Finished) { m_engineType = NoEngineType; return; diff --git a/src/plugins/debugger/debuggeritemmanager.cpp b/src/plugins/debugger/debuggeritemmanager.cpp index c02a87f9c2..4cfe7cf154 100644 --- a/src/plugins/debugger/debuggeritemmanager.cpp +++ b/src/plugins/debugger/debuggeritemmanager.cpp @@ -228,8 +228,8 @@ void DebuggerItemManager::autoDetectGdbOrLldbDebuggers() SynchronousProcess lldbInfo; lldbInfo.setTimeoutS(2); SynchronousProcessResponse response - = lldbInfo.run(QLatin1String("xcrun"), QStringList() << QLatin1String("--find") - << QLatin1String("lldb")); + = lldbInfo.runBlocking(QLatin1String("xcrun"), QStringList() << QLatin1String("--find") + << QLatin1String("lldb")); if (response.result == Utils::SynchronousProcessResponse::Finished) { QString lPath = response.allOutput(); if (!lPath.isEmpty()) { diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index 6529d87c60..a0fddc6380 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -140,7 +140,7 @@ GdbCoreEngine::readExecutableNameFromCore(const QString &debuggerCommand, const QStringList envLang = QProcess::systemEnvironment(); Utils::Environment::setupEnglishOutput(&envLang); proc.setEnvironment(envLang); - SynchronousProcessResponse response = proc.run(debuggerCommand, args); + SynchronousProcessResponse response = proc.runBlocking(debuggerCommand, args); if (response.result == SynchronousProcessResponse::Finished) { QString output = response.stdOut; diff --git a/src/plugins/projectexplorer/abstractmsvctoolchain.cpp b/src/plugins/projectexplorer/abstractmsvctoolchain.cpp index badc4b4c1a..d7eb341d5b 100644 --- a/src/plugins/projectexplorer/abstractmsvctoolchain.cpp +++ b/src/plugins/projectexplorer/abstractmsvctoolchain.cpp @@ -279,7 +279,7 @@ bool AbstractMsvcToolChain::generateEnvironmentSettings(Utils::Environment &env, if (debug) qDebug() << "readEnvironmentSetting: " << call << cmdPath << cmdArguments.join(' ') << " Env: " << env.size(); - Utils::SynchronousProcessResponse response = run.run(cmdPath.toString(), cmdArguments); + Utils::SynchronousProcessResponse response = run.runBlocking(cmdPath.toString(), cmdArguments); if (response.result != Utils::SynchronousProcessResponse::Finished) { qWarning() << response.exitMessage(cmdPath.toString(), 10); return false; diff --git a/src/plugins/projectexplorer/msvctoolchain.cpp b/src/plugins/projectexplorer/msvctoolchain.cpp index 1d8df3ac33..902c315db8 100644 --- a/src/plugins/projectexplorer/msvctoolchain.cpp +++ b/src/plugins/projectexplorer/msvctoolchain.cpp @@ -248,7 +248,7 @@ QByteArray MsvcToolChain::msvcPredefinedMacros(const QStringList cxxflags, } arguments << toProcess << QLatin1String("/EP") << QDir::toNativeSeparators(saver.fileName()); - Utils::SynchronousProcessResponse response = cpp.run(binary.toString(), arguments); + Utils::SynchronousProcessResponse response = cpp.runBlocking(binary.toString(), arguments); if (response.result != Utils::SynchronousProcessResponse::Finished || response.exitCode != 0) return predefinedMacros; diff --git a/src/plugins/texteditor/generichighlighter/highlightersettings.cpp b/src/plugins/texteditor/generichighlighter/highlightersettings.cpp index 545d04101c..dcfa90593f 100644 --- a/src/plugins/texteditor/generichighlighter/highlightersettings.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightersettings.cpp @@ -72,7 +72,7 @@ QString findFallbackDefinitionsLocation() Utils::SynchronousProcess process; process.setTimeoutS(5); Utils::SynchronousProcessResponse response - = process.run(program, QStringList(QLatin1String("--prefix"))); + = process.runBlocking(program, QStringList(QLatin1String("--prefix"))); if (response.result == Utils::SynchronousProcessResponse::Finished) { QString output = response.stdOut; output.remove(QLatin1Char('\n')); -- cgit v1.2.1