diff options
author | Jarek Kobus <[email protected]> | 2022-05-06 02:16:54 +0200 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2022-05-09 07:42:02 +0000 |
commit | d8ee25ec3db039368ac0440af647fd7afd80079b (patch) | |
tree | de55d7076c9902cfb11fa0ba447a14667cf52223 /src | |
parent | 48d1bd0551243ed541068f0c52f72bac81041997 (diff) |
Move setupSshEnvironment() into SshConnectionParameters
As we are going to remove SshRemoteProcess.
Change-Id: I07cf246791f1adb6cfc454935d7e330c2f1d4dc7
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/ssh/sftptransfer.cpp | 5 | ||||
-rw-r--r-- | src/libs/ssh/sshconnection.cpp | 22 | ||||
-rw-r--r-- | src/libs/ssh/sshconnection.h | 4 | ||||
-rw-r--r-- | src/libs/ssh/sshremoteprocess.cpp | 22 | ||||
-rw-r--r-- | src/libs/ssh/sshremoteprocess.h | 2 | ||||
-rw-r--r-- | src/plugins/remotelinux/linuxdevice.cpp | 7 | ||||
-rw-r--r-- | src/plugins/remotelinux/linuxdevicetester.cpp | 8 | ||||
-rw-r--r-- | src/plugins/remotelinux/rsyncdeploystep.cpp | 3 |
8 files changed, 38 insertions, 35 deletions
diff --git a/src/libs/ssh/sftptransfer.cpp b/src/libs/ssh/sftptransfer.cpp index 55b7489d4b7..2151bc0817e 100644 --- a/src/libs/ssh/sftptransfer.cpp +++ b/src/libs/ssh/sftptransfer.cpp @@ -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; diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index 7d2d0d8f5c0..145a2f60bcd 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -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() diff --git a/src/libs/ssh/sshconnection.h b/src/libs/ssh/sshconnection.h index 2e8a707c8fc..b2d2abc27ad 100644 --- a/src/libs/ssh/sshconnection.h +++ b/src/libs/ssh/sshconnection.h @@ -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); diff --git a/src/libs/ssh/sshremoteprocess.cpp b/src/libs/ssh/sshremoteprocess.cpp index 7c4b089fd82..f0b52d5ff27 100644 --- a/src/libs/ssh/sshremoteprocess.cpp +++ b/src/libs/ssh/sshremoteprocess.cpp @@ -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 diff --git a/src/libs/ssh/sshremoteprocess.h b/src/libs/ssh/sshremoteprocess.h index 9c011bfa64e..cfd6427c732 100644 --- a/src/libs/ssh/sshremoteprocess.h +++ b/src/libs/ssh/sshremoteprocess.h @@ -46,8 +46,6 @@ public: Utils::CommandLine fullLocalCommandLine(bool inTerminal = false) const; - static bool setupSshEnvironment(Utils::QtcProcess *process); - protected: void emitFinished() override; diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 77824db8d98..b41c5d80264 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -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 }; diff --git a/src/plugins/remotelinux/linuxdevicetester.cpp b/src/plugins/remotelinux/linuxdevicetester.cpp index 34fcca487d6..ffa745890e4 100644 --- a/src/plugins/remotelinux/linuxdevicetester.cpp +++ b/src/plugins/remotelinux/linuxdevicetester.cpp @@ -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() diff --git a/src/plugins/remotelinux/rsyncdeploystep.cpp b/src/plugins/remotelinux/rsyncdeploystep.cpp index 355e1441161..2f6b3c145dc 100644 --- a/src/plugins/remotelinux/rsyncdeploystep.cpp +++ b/src/plugins/remotelinux/rsyncdeploystep.cpp @@ -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; } |