aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2018-11-23 11:07:57 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2018-12-13 15:10:11 +0000
commitd7178b88c4b2572fb83b28f8178940766216deed (patch)
tree861eb8069fb97c8e8e79f56cb8f88f05126639fc /src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
parent030d4d01084b04af361f07dd6360dfad8e2cc19c (diff)
SSH: Use OpenSSH tools
... instead of our own SSH library. Advantages: - Full compatibility with OpenSSH behavior guaranteed. - Minimal maintenance effort. - Less code to build. - Big chunk of 3rd party sources can be removed from our repository. One the downside, Windows users now need to install OpenSSH for RemoteLinux support. Hoewever, people doing embedded development probably have it installed anyway. [ChangeLog] Switched SSH backend to OpenSSH Fixes: QTCREATORBUG-15744 Fixes: QTCREATORBUG-15807 Fixes: QTCREATORBUG-19306 Fixes: QTCREATORBUG-20210 Change-Id: Ifcfefdd39401e45ba1f4aca35d2c5bf7046c7aab Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp')
-rw-r--r--src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp110
1 files changed, 39 insertions, 71 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp b/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
index 9feb7e7166..e3cc959a5d 100644
--- a/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
+++ b/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
@@ -39,18 +39,19 @@
namespace ProjectExplorer {
+enum class Signal { Interrupt, Terminate, Kill };
+
class SshDeviceProcess::SshDeviceProcessPrivate
{
public:
SshDeviceProcessPrivate(SshDeviceProcess *q) : q(q) {}
SshDeviceProcess * const q;
- bool serverSupportsSignals = false;
QSsh::SshConnection *connection = nullptr;
- QSsh::SshRemoteProcess::Ptr process;
+ QSsh::SshRemoteProcessPtr process;
Runnable runnable;
QString errorMessage;
- QSsh::SshRemoteProcess::ExitStatus exitStatus;
+ QProcess::ExitStatus exitStatus = QProcess::NormalExit;
DeviceProcessSignalOperation::Ptr killOperation;
QTimer killTimer;
QByteArray stdOut;
@@ -59,7 +60,7 @@ public:
enum State { Inactive, Connecting, Connected, ProcessRunning } state = Inactive;
void setState(State newState);
- void doSignal(QSsh::SshRemoteProcess::Signal signal);
+ void doSignal(Signal signal);
QString displayName() const
{
@@ -85,15 +86,12 @@ void SshDeviceProcess::start(const Runnable &runnable)
d->errorMessage.clear();
d->exitCode = -1;
+ d->exitStatus = QProcess::NormalExit;
d->runnable = runnable;
- d->connection = QSsh::acquireConnection(device()->sshParameters());
- const QString displayName = d->displayName();
- const QString connDisplayName = d->connection->x11DisplayName();
- if (!displayName.isEmpty() && !connDisplayName.isEmpty() && connDisplayName != displayName) {
- QSsh::releaseConnection(d->connection);
- d->connection = new QSsh::SshConnection(device()->sshParameters(), this);
- }
- connect(d->connection, &QSsh::SshConnection::error,
+ QSsh::SshConnectionParameters params = device()->sshParameters();
+ params.x11DisplayName = d->displayName();
+ d->connection = QSsh::acquireConnection(params);
+ connect(d->connection, &QSsh::SshConnection::errorOccurred,
this, &SshDeviceProcess::handleConnectionError);
connect(d->connection, &QSsh::SshConnection::disconnected,
this, &SshDeviceProcess::handleDisconnected);
@@ -110,17 +108,17 @@ void SshDeviceProcess::start(const Runnable &runnable)
void SshDeviceProcess::interrupt()
{
QTC_ASSERT(d->state == SshDeviceProcessPrivate::ProcessRunning, return);
- d->doSignal(QSsh::SshRemoteProcess::IntSignal);
+ d->doSignal(Signal::Interrupt);
}
void SshDeviceProcess::terminate()
{
- d->doSignal(QSsh::SshRemoteProcess::TermSignal);
+ d->doSignal(Signal::Terminate);
}
void SshDeviceProcess::kill()
{
- d->doSignal(QSsh::SshRemoteProcess::KillSignal);
+ d->doSignal(Signal::Kill);
}
QProcess::ProcessState SshDeviceProcess::state() const
@@ -169,11 +167,6 @@ QByteArray SshDeviceProcess::readAllStandardError()
return data;
}
-void SshDeviceProcess::setSshServerSupportsSignals(bool signalsSupported)
-{
- d->serverSupportsSignals = signalsSupported;
-}
-
qint64 SshDeviceProcess::processId() const
{
return 0;
@@ -185,15 +178,11 @@ void SshDeviceProcess::handleConnected()
d->setState(SshDeviceProcessPrivate::Connected);
d->process = d->connection->createRemoteProcess(fullCommandLine(d->runnable).toUtf8());
- connect(d->process.data(), &QSsh::SshRemoteProcess::started, this, &SshDeviceProcess::handleProcessStarted);
- connect(d->process.data(), &QSsh::SshRemoteProcess::closed, this, &SshDeviceProcess::handleProcessFinished);
- connect(d->process.data(), &QSsh::SshRemoteProcess::readyReadStandardOutput, this, &SshDeviceProcess::handleStdout);
- connect(d->process.data(), &QSsh::SshRemoteProcess::readyReadStandardError, this, &SshDeviceProcess::handleStderr);
-
- d->process->clearEnvironment();
- const Utils::Environment env = d->runnable.environment;
- for (Utils::Environment::const_iterator it = env.constBegin(); it != env.constEnd(); ++it)
- d->process->addToEnvironment(env.key(it).toUtf8(), env.value(it).toUtf8());
+ connect(d->process.get(), &QSsh::SshRemoteProcess::started, this, &SshDeviceProcess::handleProcessStarted);
+ connect(d->process.get(), &QSsh::SshRemoteProcess::done, this, &SshDeviceProcess::handleProcessFinished);
+ connect(d->process.get(), &QSsh::SshRemoteProcess::readyReadStandardOutput, this, &SshDeviceProcess::handleStdout);
+ connect(d->process.get(), &QSsh::SshRemoteProcess::readyReadStandardError, this, &SshDeviceProcess::handleStderr);
+
const QString display = d->displayName();
if (!display.isEmpty())
d->process->requestX11Forwarding(display);
@@ -234,24 +223,10 @@ void SshDeviceProcess::handleProcessStarted()
emit started();
}
-void SshDeviceProcess::handleProcessFinished(int exitStatus)
+void SshDeviceProcess::handleProcessFinished()
{
- d->exitStatus = static_cast<QSsh::SshRemoteProcess::ExitStatus>(exitStatus);
- switch (d->exitStatus) {
- case QSsh::SshRemoteProcess::FailedToStart:
- QTC_ASSERT(d->state == SshDeviceProcessPrivate::Connected, return);
- break;
- case QSsh::SshRemoteProcess::CrashExit:
- QTC_ASSERT(d->state == SshDeviceProcessPrivate::ProcessRunning, return);
- break;
- case QSsh::SshRemoteProcess::NormalExit:
- QTC_ASSERT(d->state == SshDeviceProcessPrivate::ProcessRunning, return);
- d->exitCode = d->process->exitCode();
- break;
- default:
- QTC_ASSERT(false, return);
- }
d->errorMessage = d->process->errorString();
+ d->exitCode = d->process->exitCode();
d->setState(SshDeviceProcessPrivate::Inactive);
emit finished();
}
@@ -302,7 +277,7 @@ QString SshDeviceProcess::fullCommandLine(const Runnable &runnable) const
return cmdLine;
}
-void SshDeviceProcess::SshDeviceProcessPrivate::doSignal(QSsh::SshRemoteProcess::Signal signal)
+void SshDeviceProcess::SshDeviceProcessPrivate::doSignal(Signal signal)
{
switch (state) {
case SshDeviceProcessPrivate::Inactive:
@@ -315,28 +290,24 @@ void SshDeviceProcess::SshDeviceProcessPrivate::doSignal(QSsh::SshRemoteProcess:
break;
case SshDeviceProcessPrivate::Connected:
case SshDeviceProcessPrivate::ProcessRunning:
- if (serverSupportsSignals) {
- process->sendSignal(signal);
+ DeviceProcessSignalOperation::Ptr signalOperation = q->device()->signalOperation();
+ quint64 processId = q->processId();
+ if (signal == Signal::Interrupt) {
+ if (processId != 0)
+ signalOperation->interruptProcess(processId);
+ else
+ signalOperation->interruptProcess(runnable.executable);
} else {
- DeviceProcessSignalOperation::Ptr signalOperation = q->device()->signalOperation();
- quint64 processId = q->processId();
- if (signal == QSsh::SshRemoteProcess::IntSignal) {
- if (processId != 0)
- signalOperation->interruptProcess(processId);
- else
- signalOperation->interruptProcess(runnable.executable);
- } else {
- if (killOperation) // We are already in the process of killing the app.
- return;
- killOperation = signalOperation;
- connect(signalOperation.data(), &DeviceProcessSignalOperation::finished, q,
- &SshDeviceProcess::handleKillOperationFinished);
- killTimer.start(5000);
- if (processId != 0)
- signalOperation->killProcess(processId);
- else
- signalOperation->killProcess(runnable.executable);
- }
+ if (killOperation) // We are already in the process of killing the app.
+ return;
+ killOperation = signalOperation;
+ connect(signalOperation.data(), &DeviceProcessSignalOperation::finished, q,
+ &SshDeviceProcess::handleKillOperationFinished);
+ killTimer.start(5000);
+ if (processId != 0)
+ signalOperation->killProcess(processId);
+ else
+ signalOperation->killProcess(runnable.executable);
}
break;
}
@@ -360,10 +331,7 @@ void SshDeviceProcess::SshDeviceProcessPrivate::setState(SshDeviceProcess::SshDe
process->disconnect(q);
if (connection) {
connection->disconnect(q);
- if (connection->parent() == q)
- connection->deleteLater();
- else
- QSsh::releaseConnection(connection);
+ QSsh::releaseConnection(connection);
connection = nullptr;
}
}