Get rid of no-op calls to QtcProcess::kill()

Leave the work for implicit ProcessReaper.

Change-Id: Ie01c4e996fda18b7cee77851394174556c6f3857
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-03-22 16:51:38 +01:00
parent 4ced33f4fe
commit 1b5c4504af
11 changed files with 25 additions and 55 deletions

View File

@@ -70,7 +70,7 @@ std::future<QProcessUniquePointer> ProcessCreator::createProcess() const
{ {
return std::async(std::launch::async, [&] { return std::async(std::launch::async, [&] {
checkIfProcessPathExists(); checkIfProcessPathExists();
auto process = QProcessUniquePointer(new QtcProcess()); auto process = QProcessUniquePointer(new QtcProcess);
process->setProcessChannelMode(QProcess::ForwardedChannels); process->setProcessChannelMode(QProcess::ForwardedChannels);
process->setEnvironment(processEnvironment()); process->setEnvironment(processEnvironment());
process->setCommand(CommandLine(FilePath::fromString(m_processPath), m_arguments)); process->setCommand(CommandLine(FilePath::fromString(m_processPath), m_arguments));

View File

@@ -294,7 +294,7 @@ bool AndroidAvdManager::startAvdAsync(const QString &avdName) const
.arg(m_config.emulatorToolPath().toString())); .arg(m_config.emulatorToolPath().toString()));
return false; return false;
} }
auto avdProcess = new QtcProcess(); auto avdProcess = new QtcProcess;
avdProcess->setProcessChannelMode(QProcess::MergedChannels); avdProcess->setProcessChannelMode(QProcess::MergedChannels);
QObject::connect(avdProcess, &QtcProcess::finished, avdProcess, QObject::connect(avdProcess, &QtcProcess::finished, avdProcess,
[avdProcess] { avdProcessFinished(avdProcess->exitCode(), avdProcess); }); [avdProcess] { avdProcessFinished(avdProcess->exitCode(), avdProcess); });

View File

@@ -56,9 +56,6 @@ const char SETTINGS_NAME[] = "uncrustify";
UncrustifySettings::UncrustifySettings() : UncrustifySettings::UncrustifySettings() :
AbstractSettings(SETTINGS_NAME, ".cfg") AbstractSettings(SETTINGS_NAME, ".cfg")
{ {
connect(&m_versionProcess, &QtcProcess::finished,
this, &UncrustifySettings::parseVersionProcessResult);
setCommand("uncrustify"); setCommand("uncrustify");
m_settings.insert(USE_OTHER_FILES, QVariant(true)); m_settings.insert(USE_OTHER_FILES, QVariant(true));
m_settings.insert(USE_HOME_FILE, QVariant(false)); m_settings.insert(USE_HOME_FILE, QVariant(false));
@@ -70,6 +67,8 @@ UncrustifySettings::UncrustifySettings() :
read(); read();
} }
UncrustifySettings::~UncrustifySettings() = default;
bool UncrustifySettings::useOtherFiles() const bool UncrustifySettings::useOtherFiles() const
{ {
return m_settings.value(USE_OTHER_FILES).toBool(); return m_settings.value(USE_OTHER_FILES).toBool();
@@ -227,21 +226,16 @@ static bool parseVersion(const QString &text, int &version)
void UncrustifySettings::updateVersion() void UncrustifySettings::updateVersion()
{ {
if (m_versionProcess.state() != QProcess::NotRunning) { m_versionProcess.reset(new QtcProcess);
m_versionProcess.kill(); connect(m_versionProcess.get(), &QtcProcess::finished, this, [this] {
m_versionProcess.waitForFinished(); if (m_versionProcess->exitStatus() == QProcess::NormalExit) {
if (!parseVersion(QString::fromUtf8(m_versionProcess->readAllStandardOutput()), m_version))
parseVersion(QString::fromUtf8(m_versionProcess->readAllStandardError()), m_version);
} }
m_versionProcess.setCommand({ command(), { "--version" } }); m_versionProcess.release()->deleteLater();
m_versionProcess.start(); });
} m_versionProcess->setCommand({ command(), { "--version" } });
m_versionProcess->start();
void UncrustifySettings::parseVersionProcessResult()
{
if (m_versionProcess.exitStatus() != QProcess::NormalExit)
return;
if (!parseVersion(QString::fromUtf8(m_versionProcess.readAllStandardOutput()), m_version))
parseVersion(QString::fromUtf8(m_versionProcess.readAllStandardError()), m_version);
} }
} // namespace Internal } // namespace Internal

View File

@@ -27,7 +27,8 @@
#include "../abstractsettings.h" #include "../abstractsettings.h"
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/qtcprocess.h>
namespace Utils { class QtcProcess; }
namespace Beautifier { namespace Beautifier {
namespace Internal { namespace Internal {
@@ -38,6 +39,7 @@ class UncrustifySettings : public AbstractSettings
public: public:
UncrustifySettings(); UncrustifySettings();
~UncrustifySettings() override;
bool useOtherFiles() const; bool useOtherFiles() const;
void setUseOtherFiles(bool useOtherFiles); void setUseOtherFiles(bool useOtherFiles);
@@ -66,8 +68,7 @@ public:
void setUseSpecificConfigFile(bool useConfigFile); void setUseSpecificConfigFile(bool useConfigFile);
private: private:
Utils::QtcProcess m_versionProcess; std::unique_ptr<Utils::QtcProcess> m_versionProcess;
void parseVersionProcessResult();
}; };
} // namespace Internal } // namespace Internal

View File

@@ -186,7 +186,7 @@ void ExecuteFilter::createProcess()
if (m_process) if (m_process)
return; return;
m_process = new Utils::QtcProcess(); m_process = new Utils::QtcProcess;
m_process->setEnvironment(Utils::Environment::systemEnvironment()); m_process->setEnvironment(Utils::Environment::systemEnvironment());
connect(m_process, &QtcProcess::finished, this, &ExecuteFilter::finished); connect(m_process, &QtcProcess::finished, this, &ExecuteFilter::finished);
connect(m_process, &QtcProcess::readyReadStandardOutput, this, &ExecuteFilter::readStandardOutput); connect(m_process, &QtcProcess::readyReadStandardOutput, this, &ExecuteFilter::readStandardOutput);

View File

@@ -106,7 +106,6 @@ ChangeSelectionDialog::ChangeSelectionDialog(const FilePath &workingDirectory, I
ChangeSelectionDialog::~ChangeSelectionDialog() ChangeSelectionDialog::~ChangeSelectionDialog()
{ {
terminateProcess();
delete m_ui; delete m_ui;
} }
@@ -182,16 +181,6 @@ void ChangeSelectionDialog::enableButtons(bool b)
m_ui->checkoutButton->setEnabled(b); m_ui->checkoutButton->setEnabled(b);
} }
void ChangeSelectionDialog::terminateProcess()
{
if (!m_process)
return;
m_process->kill();
m_process->waitForFinished();
delete m_process;
m_process = nullptr;
}
void ChangeSelectionDialog::recalculateCompletion() void ChangeSelectionDialog::recalculateCompletion()
{ {
const FilePath workingDir = workingDirectory(); const FilePath workingDir = workingDirectory();
@@ -214,7 +203,6 @@ void ChangeSelectionDialog::recalculateCompletion()
void ChangeSelectionDialog::recalculateDetails() void ChangeSelectionDialog::recalculateDetails()
{ {
terminateProcess();
enableButtons(true); enableButtons(true);
const FilePath workingDir = workingDirectory(); const FilePath workingDir = workingDirectory();
@@ -229,12 +217,12 @@ void ChangeSelectionDialog::recalculateDetails()
return; return;
} }
m_process = new QtcProcess(this); m_process.reset(new QtcProcess);
m_process->setWorkingDirectory(workingDir); m_process->setWorkingDirectory(workingDir);
m_process->setEnvironment(m_gitEnvironment); m_process->setEnvironment(m_gitEnvironment);
m_process->setCommand({m_gitExecutable, {"show", "--decorate", "--stat=80", ref}}); m_process->setCommand({m_gitExecutable, {"show", "--decorate", "--stat=80", ref}});
connect(m_process, &QtcProcess::finished, this, &ChangeSelectionDialog::setDetails); connect(m_process.get(), &QtcProcess::finished, this, &ChangeSelectionDialog::setDetails);
m_process->start(); m_process->start();
if (!m_process->waitForStarted()) if (!m_process->waitForStarted())

View File

@@ -72,11 +72,10 @@ private:
void acceptCommand(ChangeCommand command); void acceptCommand(ChangeCommand command);
void enableButtons(bool b); void enableButtons(bool b);
void terminateProcess();
Ui::ChangeSelectionDialog *m_ui; Ui::ChangeSelectionDialog *m_ui;
Utils::QtcProcess *m_process = nullptr; std::unique_ptr<Utils::QtcProcess> m_process;
Utils::FilePath m_gitExecutable; Utils::FilePath m_gitExecutable;
Utils::Environment m_gitEnvironment; Utils::Environment m_gitEnvironment;
ChangeCommand m_command = NoCommand; ChangeCommand m_command = NoCommand;

View File

@@ -80,15 +80,7 @@ PerfTracePointDialog::PerfTracePointDialog() :
? QLatin1String("pkexec") : QLatin1String("n.a.")); ? QLatin1String("pkexec") : QLatin1String("n.a."));
} }
PerfTracePointDialog::~PerfTracePointDialog() PerfTracePointDialog::~PerfTracePointDialog() = default;
{
if (m_process && m_process->state() != QProcess::NotRunning) {
QtcProcess *process = m_process.release();
connect(process, &QtcProcess::finished, process, &QObject::deleteLater);
process->kill();
QTimer::singleShot(10000, process, &QObject::deleteLater);
}
}
void PerfTracePointDialog::runScript() void PerfTracePointDialog::runScript()
{ {

View File

@@ -216,7 +216,7 @@ void AbstractProcessStep::doRun()
? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale()); ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale());
d->stderrStream = std::make_unique<QTextDecoder>(QTextCodec::codecForLocale()); d->stderrStream = std::make_unique<QTextDecoder>(QTextCodec::codecForLocale());
d->m_process.reset(new QtcProcess()); d->m_process.reset(new QtcProcess);
d->m_process->setUseCtrlCStub(HostOsInfo::isWindowsHost()); d->m_process->setUseCtrlCStub(HostOsInfo::isWindowsHost());
d->m_process->setWorkingDirectory(wd); d->m_process->setWorkingDirectory(wd);
// Enforce PWD in the environment because some build tools use that. // Enforce PWD in the environment because some build tools use that.

View File

@@ -426,11 +426,8 @@ void ProcessExtraCompiler::runInThread(
if (process.waitForFinished(200)) if (process.waitForFinished(200))
break; break;
if (futureInterface.isCanceled()) { if (futureInterface.isCanceled())
process.kill();
process.waitForFinished();
return; return;
}
futureInterface.reportResult(handleProcessFinished(&process)); futureInterface.reportResult(handleProcessFinished(&process));
} }

View File

@@ -127,7 +127,6 @@ static FormatTask format(FormatTask task)
return task; return task;
} }
if (!process.waitForFinished(5000)) { if (!process.waitForFinished(5000)) {
process.kill();
task.error = QString(QT_TRANSLATE_NOOP("TextEditor", task.error = QString(QT_TRANSLATE_NOOP("TextEditor",
"Cannot call %1 or some other error occurred. Timeout " "Cannot call %1 or some other error occurred. Timeout "
"reached while formatting file %2.")) "reached while formatting file %2."))