forked from qt-creator/qt-creator
Deviceshell: Cleanup shellProcess destruction
Change-Id: I71507d9e74979fca461784575257e7bafd1b4838 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -187,12 +187,12 @@ DeviceShell::DeviceShell()
|
||||
|
||||
DeviceShell::~DeviceShell()
|
||||
{
|
||||
m_shellProcess->deleteLater();
|
||||
|
||||
if (m_thread.isRunning()) {
|
||||
m_thread.quit();
|
||||
m_thread.wait();
|
||||
}
|
||||
|
||||
QTC_CHECK(!m_shellProcess);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -247,7 +247,7 @@ DeviceShell::RunResult DeviceShell::run(const CommandLine &cmd, const QByteArray
|
||||
const int id = ++m_currentId;
|
||||
const auto it = m_commandOutput.insert(id, CommandRun{{-1, {}, {}}, &waiter});
|
||||
|
||||
QMetaObject::invokeMethod(m_shellProcess, [this, id, cmd, stdInData]() {
|
||||
QMetaObject::invokeMethod(m_shellProcess.get(), [this, id, cmd, stdInData]() {
|
||||
const QString command = QString("%1 \"%2\" %3\n")
|
||||
.arg(id)
|
||||
.arg(QString::fromLatin1(stdInData.toBase64()))
|
||||
@@ -302,13 +302,12 @@ void DeviceShell::startupFailed(const CommandLine &cmdLine)
|
||||
*/
|
||||
bool DeviceShell::start()
|
||||
{
|
||||
m_shellProcess = new QtcProcess();
|
||||
connect(m_shellProcess, &QtcProcess::done, m_shellProcess,
|
||||
m_shellProcess = std::make_unique<QtcProcess>();
|
||||
connect(m_shellProcess.get(), &QtcProcess::done, m_shellProcess.get(),
|
||||
[this] { emit done(m_shellProcess->resultData()); });
|
||||
connect(m_shellProcess, &QObject::destroyed, this, [this] { m_shellProcess = nullptr; });
|
||||
connect(&m_thread, &QThread::finished, m_shellProcess, [this] { closeShellProcess(); });
|
||||
connect(&m_thread, &QThread::finished, m_shellProcess.get(), [this] { closeShellProcess(); }, Qt::DirectConnection);
|
||||
|
||||
setupShellProcess(m_shellProcess);
|
||||
setupShellProcess(m_shellProcess.get());
|
||||
|
||||
m_shellProcess->setProcessMode(ProcessMode::Writer);
|
||||
|
||||
@@ -317,7 +316,7 @@ bool DeviceShell::start()
|
||||
|
||||
bool result = false;
|
||||
QMetaObject::invokeMethod(
|
||||
m_shellProcess,
|
||||
m_shellProcess.get(),
|
||||
[this] {
|
||||
m_shellProcess->start();
|
||||
|
||||
@@ -326,10 +325,10 @@ bool DeviceShell::start()
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(m_shellProcess, &QtcProcess::readyReadStandardOutput, m_shellProcess, [this] {
|
||||
connect(m_shellProcess.get(), &QtcProcess::readyReadStandardOutput, m_shellProcess.get(), [this] {
|
||||
onReadyRead();
|
||||
});
|
||||
connect(m_shellProcess, &QtcProcess::readyReadStandardError, m_shellProcess, [this] {
|
||||
connect(m_shellProcess.get(), &QtcProcess::readyReadStandardError, m_shellProcess.get(), [this] {
|
||||
const QByteArray stdErr = m_shellProcess->readAllStandardError();
|
||||
|
||||
if (m_shellScriptState == State::Unknown) {
|
||||
@@ -347,7 +346,7 @@ bool DeviceShell::start()
|
||||
qCWarning(deviceShellLog) << "Received unexpected output on stderr:" << stdErr;
|
||||
});
|
||||
|
||||
connect(m_shellProcess, &QtcProcess::done, m_shellProcess, [this]() {
|
||||
connect(m_shellProcess.get(), &QtcProcess::done, m_shellProcess.get(), [this] {
|
||||
if (m_shellProcess->resultData().m_exitCode != EXIT_SUCCESS
|
||||
|| m_shellProcess->resultData().m_exitStatus != QProcess::NormalExit) {
|
||||
qCWarning(deviceShellLog) << "Shell exited with error code:"
|
||||
@@ -400,6 +399,7 @@ void DeviceShell::closeShellProcess()
|
||||
if (!m_shellProcess->waitForFinished(2000))
|
||||
m_shellProcess->terminate();
|
||||
}
|
||||
m_shellProcess.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -96,7 +96,7 @@ private:
|
||||
QWaitCondition *waiter;
|
||||
};
|
||||
|
||||
QtcProcess *m_shellProcess = nullptr;
|
||||
std::unique_ptr<QtcProcess> m_shellProcess;
|
||||
QThread m_thread;
|
||||
int m_currentId{0};
|
||||
|
||||
|
@@ -1027,6 +1027,7 @@ QtcProcess::QtcProcess(QObject *parent)
|
||||
: QObject(parent),
|
||||
d(new QtcProcessPrivate(this))
|
||||
{
|
||||
qRegisterMetaType<ProcessResultData>("ProcessResultData");
|
||||
static int qProcessExitStatusMeta = qRegisterMetaType<QProcess::ExitStatus>();
|
||||
static int qProcessProcessErrorMeta = qRegisterMetaType<QProcess::ProcessError>();
|
||||
Q_UNUSED(qProcessExitStatusMeta)
|
||||
|
@@ -454,7 +454,7 @@ void DockerDevicePrivate::startContainer()
|
||||
return;
|
||||
|
||||
qCWarning(dockerDeviceLog) << "Container shell encountered error:" << resultData.m_error;
|
||||
m_shell.reset();
|
||||
m_shell.release()->deleteLater();
|
||||
|
||||
DockerApi::recheckDockerDaemon();
|
||||
MessageManager::writeFlashing(tr("Docker daemon appears to be not running. "
|
||||
@@ -479,7 +479,7 @@ void DockerDevicePrivate::updateContainerAccess()
|
||||
if (m_shell)
|
||||
return;
|
||||
|
||||
startContainer();
|
||||
startContainer();
|
||||
}
|
||||
|
||||
void DockerDevice::setMounts(const QStringList &mounts) const
|
||||
|
@@ -814,7 +814,7 @@ public:
|
||||
cmd.addArg("/bin/sh");
|
||||
|
||||
m_shell.reset(new LinuxDeviceShell(cmd));
|
||||
connect(m_shell.get(), &DeviceShell::done, this, [this] { m_shell.reset(); });
|
||||
connect(m_shell.get(), &DeviceShell::done, this, [this] { m_shell.release()->deleteLater(); });
|
||||
return m_shell->start();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user