RemoteLinux: Disable sourcing /etc/profile and ~/.profile by default

[ChangeLog][RemoteLinux] Target-side shell profiles are not sourced by
default anymore.

Change-Id: Ide5029d02a0d149c4e532ee523f1dd49e7080c7b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2023-03-16 10:30:46 +01:00
parent dea3ea2262
commit 024897521c
5 changed files with 28 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
#include "genericlinuxdeviceconfigurationwidget.h"
#include "remotelinux_constants.h"
#include "remotelinuxtr.h"
#include "sshkeycreationdialog.h"
@@ -80,6 +81,9 @@ GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget(
m_qmlRuntimeLineEdit->setPlaceholderText(hint);
m_qmlRuntimeLineEdit->setToolTip(hint);
m_sourceProfileCheckBox =
new QCheckBox(Tr::tr("Source %1 and %2").arg("/etc/profile").arg("$HOME/.profile"));
auto sshPortLabel = new QLabel(Tr::tr("&SSH port:"));
sshPortLabel->setBuddy(m_sshPortSpinBox);
@@ -93,7 +97,8 @@ GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget(
Tr::tr("&Username:"), m_userLineEdit, st, br,
m_keyLabel, m_keyFileLineEdit, createKeyButton, br,
Tr::tr("GDB server executable:"), m_gdbServerLineEdit, br,
Tr::tr("QML runtime executable:"), m_qmlRuntimeLineEdit, br
Tr::tr("QML runtime executable:"), m_qmlRuntimeLineEdit, br,
QString(), m_sourceProfileCheckBox, br
}.attachTo(this);
connect(m_hostLineEdit, &QLineEdit::editingFinished,
@@ -124,6 +129,8 @@ GenericLinuxDeviceConfigurationWidget::GenericLinuxDeviceConfigurationWidget(
this, &GenericLinuxDeviceConfigurationWidget::qmlRuntimeEditingFinished);
connect(m_hostKeyCheckBox, &QCheckBox::toggled,
this, &GenericLinuxDeviceConfigurationWidget::hostKeyCheckingChanged);
connect(m_sourceProfileCheckBox, &QCheckBox::toggled,
this, &GenericLinuxDeviceConfigurationWidget::sourceProfileCheckingChanged);
initGui();
}
@@ -214,6 +221,11 @@ void GenericLinuxDeviceConfigurationWidget::hostKeyCheckingChanged(bool doCheck)
device()->setSshParameters(sshParams);
}
void GenericLinuxDeviceConfigurationWidget::sourceProfileCheckingChanged(bool doCheck)
{
device()->setExtraData(Constants::SourceProfile, doCheck);
}
void GenericLinuxDeviceConfigurationWidget::updateDeviceFromUi()
{
hostNameEditingFinished();
@@ -260,6 +272,7 @@ void GenericLinuxDeviceConfigurationWidget::initGui()
m_hostLineEdit->setEnabled(!device()->isAutoDetected());
m_sshPortSpinBox->setEnabled(!device()->isAutoDetected());
m_hostKeyCheckBox->setChecked(sshParams.hostKeyCheckingMode != SshHostKeyCheckingNone);
m_sourceProfileCheckBox->setChecked(device()->extraData(Constants::SourceProfile).toBool());
m_hostLineEdit->setText(sshParams.host());
m_sshPortSpinBox->setValue(sshParams.port());

View File

@@ -42,6 +42,7 @@ private:
void setPrivateKey(const Utils::FilePath &path);
void createNewKey();
void hostKeyCheckingChanged(bool doCheck);
void sourceProfileCheckingChanged(bool doCheck);
void updateDeviceFromUi() override;
void updatePortsWarningLabel();
@@ -61,6 +62,7 @@ private:
QLabel *m_machineTypeValueLabel;
Utils::PathChooser *m_gdbServerLineEdit;
Utils::PathChooser *m_qmlRuntimeLineEdit;
QCheckBox *m_sourceProfileCheckBox;
};
} // RemoteLinux::Internal

View File

@@ -464,6 +464,11 @@ bool SshProcessInterface::runInShell(const CommandLine &command, const QByteArra
return isFinished;
}
IDevice::ConstPtr SshProcessInterface::device() const
{
return d->m_device;
}
void SshProcessInterface::start()
{
d->start();
@@ -520,7 +525,7 @@ QString LinuxProcessInterface::fullCommandLine(const CommandLine &commandLine) c
{
CommandLine cmd;
if (!commandLine.isEmpty()) {
if (!commandLine.isEmpty() && device()->extraData(Constants::SourceProfile).toBool()) {
const QStringList rcFilesToSource = {"/etc/profile", "$HOME/.profile"};
for (const QString &filePath : rcFilesToSource) {
cmd.addArgs({"test", "-f", filePath});
@@ -730,6 +735,7 @@ void SshProcessInterfacePrivate::doStart()
env.set("DISPLAY", m_sshParameters.x11DisplayName);
m_process.setControlEnvironment(env);
}
m_process.setExtraData(q->m_setup.m_extraData);
m_process.setCommand(fullLocalCommandLine());
m_process.start();
}

View File

@@ -20,6 +20,7 @@ const char CustomCommandDeployStepId[] = "RemoteLinux.GenericRemoteLinuxCustomCo
const char KillAppStepId[] = "RemoteLinux.KillAppStep";
const char SupportsRSync[] = "RemoteLinux.SupportsRSync";
const char SourceProfile[] = "RemoteLinux.SourceProfile";
const char RunConfigId[] = "RemoteLinuxRunConfiguration:";
const char CustomRunConfigId[] = "RemoteLinux.CustomRunConfig";

View File

@@ -5,6 +5,8 @@
#include "remotelinux_export.h"
#include <projectexplorer/devicesupport/idevice.h>
#include <utils/processinterface.h>
namespace RemoteLinux {
@@ -26,6 +28,8 @@ protected:
qint64 processId() const;
bool runInShell(const Utils::CommandLine &command, const QByteArray &data = {});
ProjectExplorer::IDevice::ConstPtr device() const;
private:
virtual void handleStarted(qint64 processId);
virtual void handleDone(const Utils::ProcessResultData &resultData);