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, [&] {
checkIfProcessPathExists();
auto process = QProcessUniquePointer(new QtcProcess());
auto process = QProcessUniquePointer(new QtcProcess);
process->setProcessChannelMode(QProcess::ForwardedChannels);
process->setEnvironment(processEnvironment());
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()));
return false;
}
auto avdProcess = new QtcProcess();
auto avdProcess = new QtcProcess;
avdProcess->setProcessChannelMode(QProcess::MergedChannels);
QObject::connect(avdProcess, &QtcProcess::finished, avdProcess,
[avdProcess] { avdProcessFinished(avdProcess->exitCode(), avdProcess); });

View File

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

View File

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

View File

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

View File

@@ -106,7 +106,6 @@ ChangeSelectionDialog::ChangeSelectionDialog(const FilePath &workingDirectory, I
ChangeSelectionDialog::~ChangeSelectionDialog()
{
terminateProcess();
delete m_ui;
}
@@ -182,16 +181,6 @@ void ChangeSelectionDialog::enableButtons(bool 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()
{
const FilePath workingDir = workingDirectory();
@@ -214,7 +203,6 @@ void ChangeSelectionDialog::recalculateCompletion()
void ChangeSelectionDialog::recalculateDetails()
{
terminateProcess();
enableButtons(true);
const FilePath workingDir = workingDirectory();
@@ -229,12 +217,12 @@ void ChangeSelectionDialog::recalculateDetails()
return;
}
m_process = new QtcProcess(this);
m_process.reset(new QtcProcess);
m_process->setWorkingDirectory(workingDir);
m_process->setEnvironment(m_gitEnvironment);
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();
if (!m_process->waitForStarted())

View File

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

View File

@@ -80,15 +80,7 @@ PerfTracePointDialog::PerfTracePointDialog() :
? QLatin1String("pkexec") : QLatin1String("n.a."));
}
PerfTracePointDialog::~PerfTracePointDialog()
{
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);
}
}
PerfTracePointDialog::~PerfTracePointDialog() = default;
void PerfTracePointDialog::runScript()
{

View File

@@ -216,7 +216,7 @@ void AbstractProcessStep::doRun()
? QTextCodec::codecForName("UTF-8") : 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->setWorkingDirectory(wd);
// Enforce PWD in the environment because some build tools use that.

View File

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

View File

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