Move setupSshEnvironment() into SshConnectionParameters

As we are going to remove SshRemoteProcess.

Change-Id: I07cf246791f1adb6cfc454935d7e330c2f1d4dc7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-06 02:16:54 +02:00
parent 48d1bd0551
commit d8ee25ec3d
9 changed files with 40 additions and 35 deletions

View File

@@ -26,7 +26,7 @@
#include "sftptransfer.h"
#include "sshlogging_p.h"
#include "sshremoteprocess.h"
#include "sshconnection.h"
#include "sshsettings.h"
#include <QDir>
@@ -37,6 +37,7 @@
#include <utils/algorithm.h>
#include <utils/commandline.h>
#include <utils/qtcprocess.h>
using namespace Utils;
@@ -109,7 +110,7 @@ SftpTransfer::SftpTransfer(const FilesToTransfer &files, Internal::FileTransferT
const QStringList &connectionArgs)
: d(new SftpTransferPrivate)
{
SshRemoteProcess::setupSshEnvironment(&d->sftpProc);
SshConnectionParameters::setupSshEnvironment(&d->sftpProc);
d->files = files;
d->transferType = type;
d->errorHandlingMode = errorHandlingMode;

View File

@@ -104,6 +104,26 @@ QStringList SshConnectionParameters::connectionOptions(const FilePath &binary) c
return args;
}
bool SshConnectionParameters::setupSshEnvironment(QtcProcess *process)
{
Environment env = process->hasEnvironment() ? process->environment()
: Environment::systemEnvironment();
const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0"));
if (SshSettings::askpassFilePath().exists()) {
env.set("SSH_ASKPASS", SshSettings::askpassFilePath().toUserOutput());
// OpenSSH only uses the askpass program if DISPLAY is set, regardless of the platform.
if (!env.hasKey("DISPLAY"))
env.set("DISPLAY", ":0");
}
process->setEnvironment(env);
// Otherwise, ssh will ignore SSH_ASKPASS and read from /dev/tty directly.
process->setDisableUnixTerminal();
return hasDisplay;
}
static inline bool equals(const SshConnectionParameters &p1, const SshConnectionParameters &p2)
{
return p1.url == p2.url
@@ -129,7 +149,7 @@ struct SshConnection::SshConnectionPrivate
SshConnectionPrivate(const SshConnectionParameters &sshParameters)
: connParams(sshParameters)
{
SshRemoteProcess::setupSshEnvironment(&masterProcess);
SshConnectionParameters::setupSshEnvironment(&masterProcess);
}
QString fullProcessError()

View File

@@ -38,6 +38,8 @@
#include <memory>
namespace Utils { class QtcProcess; }
namespace QSsh {
class SshRemoteProcess;
@@ -73,6 +75,8 @@ public:
int timeout = 0; // In seconds.
AuthenticationType authenticationType = AuthenticationTypeAll;
SshHostKeyCheckingMode hostKeyCheckingMode = SshHostKeyCheckingAllowNoMatch;
static bool setupSshEnvironment(Utils::QtcProcess *process);
};
QSSH_EXPORT bool operator==(const SshConnectionParameters &p1, const SshConnectionParameters &p2);

View File

@@ -25,6 +25,7 @@
#include "sshremoteprocess.h"
#include "sshconnection.h"
#include "sshlogging_p.h"
#include "sshsettings.h"
@@ -54,7 +55,7 @@ namespace QSsh {
SshRemoteProcess::SshRemoteProcess(const QString &command, const QStringList &connectionArgs)
: QtcProcess()
{
setupSshEnvironment(this);
SshConnectionParameters::setupSshEnvironment(this);
m_remoteCommand = command;
m_connectionArgs = connectionArgs;
}
@@ -112,23 +113,4 @@ CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
return cmd;
}
bool SshRemoteProcess::setupSshEnvironment(QtcProcess *process)
{
Environment env = process->hasEnvironment() ? process->environment()
: Environment::systemEnvironment();
const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0"));
if (SshSettings::askpassFilePath().exists()) {
env.set("SSH_ASKPASS", SshSettings::askpassFilePath().toUserOutput());
// OpenSSH only uses the askpass program if DISPLAY is set, regardless of the platform.
if (!env.hasKey("DISPLAY"))
env.set("DISPLAY", ":0");
}
process->setEnvironment(env);
// Otherwise, ssh will ignore SSH_ASKPASS and read from /dev/tty directly.
process->setDisableUnixTerminal();
return hasDisplay;
}
} // namespace QSsh

View File

@@ -46,8 +46,6 @@ public:
Utils::CommandLine fullLocalCommandLine(bool inTerminal = false) const;
static bool setupSshEnvironment(Utils::QtcProcess *process);
protected:
void emitFinished() override;

View File

@@ -42,7 +42,6 @@
#include <projectexplorer/runcontrol.h>
#include <ssh/sshconnection.h>
#include <ssh/sshremoteprocess.h>
#include <ssh/sshsettings.h>
#include <utils/algorithm.h>
@@ -189,7 +188,7 @@ void SshSharedConnection::connectToHost()
}
m_masterProcess.reset(new QtcProcess);
SshRemoteProcess::setupSshEnvironment(m_masterProcess.get());
SshConnectionParameters::setupSshEnvironment(m_masterProcess.get());
m_timer.setSingleShot(true);
connect(&m_timer, &QTimer::timeout, this, &SshSharedConnection::autoDestructRequested);
connect(m_masterProcess.get(), &QtcProcess::readyReadStandardOutput, [this] {
@@ -759,7 +758,7 @@ void SshProcessInterfacePrivate::doStart()
m_process.setTerminalMode(q->m_setup.m_terminalMode);
m_process.setWriteData(q->m_setup.m_writeData);
// TODO: what about other fields from m_setup?
SshRemoteProcess::setupSshEnvironment(&m_process);
SshConnectionParameters::setupSshEnvironment(&m_process);
if (!m_sshParameters.x11DisplayName.isEmpty()) {
Environment env = m_process.environment();
// Note: it seems this is no-op when shared connection is used.
@@ -831,7 +830,7 @@ public:
setSshParameters(parameters);
m_shell.reset(new QtcProcess);
SshRemoteProcess::setupSshEnvironment(m_shell.get());
SshConnectionParameters::setupSshEnvironment(m_shell.get());
const FilePath sshPath = SshSettings::sshFilePath();
CommandLine cmd { sshPath };

View File

@@ -29,12 +29,12 @@
#include "rsyncdeploystep.h"
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
#include <utils/port.h>
#include <utils/qtcassert.h>
#include <ssh/sftptransfer.h>
#include <ssh/sshremoteprocess.h>
#include <ssh/sshconnection.h>
#include <ssh/sshconnectionmanager.h>
#include <utils/port.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
using namespace ProjectExplorer;
using namespace QSsh;
@@ -72,7 +72,7 @@ GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
&GenericLinuxDeviceTester::handleUnameFinished);
connect(&d->rsyncProcess, &QtcProcess::done, this,
&GenericLinuxDeviceTester::handleRsyncFinished);
SshRemoteProcess::setupSshEnvironment(&d->rsyncProcess);
SshConnectionParameters::setupSshEnvironment(&d->rsyncProcess);
}
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()

View File

@@ -33,7 +33,6 @@
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
#include <ssh/sshconnection.h>
#include <ssh/sshremoteprocess.h>
#include <ssh/sshsettings.h>
#include <utils/algorithm.h>
#include <utils/qtcprocess.h>
@@ -50,7 +49,7 @@ class RsyncDeployService : public AbstractRemoteLinuxDeployService
Q_OBJECT
public:
RsyncDeployService(QObject *parent = nullptr) : AbstractRemoteLinuxDeployService(parent)
{ SshRemoteProcess::setupSshEnvironment(&m_rsync); }
{ SshConnectionParameters::setupSshEnvironment(&m_rsync); }
void setDeployableFiles(const QList<DeployableFile> &files) { m_deployableFiles = files; }
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }

View File

@@ -27,6 +27,8 @@
#include <ssh/sshremoteprocess.h>
#include <utils/qtcprocess.h>
#include <QCoreApplication>
#include <QFile>
#include <QSocketNotifier>