forked from qt-creator/qt-creator
RemoteLinux: Allow killing processes by ID
Killing every process on the system that happens to have the same name as the one we've started is error prone and dangerous. We might kill processes we haven't started and other processes might rename themselves at runtime so that we don't find them anymore. The process ID is obtained by outputting it as very first thing on stdout and then starting the process with "exec", so that it isn't forked. Change-Id: Icc51bd1968afc47f4dc42f9e90e5dcbd0b1e40a7 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -39,8 +39,11 @@ static QString quote(const QString &s) { return Utils::QtcProcess::quoteArgUnix(
|
||||
|
||||
LinuxDeviceProcess::LinuxDeviceProcess(const QSharedPointer<const ProjectExplorer::IDevice> &device,
|
||||
QObject *parent)
|
||||
: ProjectExplorer::SshDeviceProcess(device, parent)
|
||||
: ProjectExplorer::SshDeviceProcess(device, parent), m_processId(0)
|
||||
{
|
||||
connect(this, &DeviceProcess::finished, this, [this]() {
|
||||
m_processId = 0;
|
||||
});
|
||||
}
|
||||
|
||||
void LinuxDeviceProcess::setRcFilesToSource(const QStringList &filePaths)
|
||||
@@ -48,6 +51,28 @@ void LinuxDeviceProcess::setRcFilesToSource(const QStringList &filePaths)
|
||||
m_rcFilesToSource = filePaths;
|
||||
}
|
||||
|
||||
QByteArray LinuxDeviceProcess::readAllStandardOutput()
|
||||
{
|
||||
QByteArray output = SshDeviceProcess::readAllStandardOutput();
|
||||
if (m_processId != 0)
|
||||
return output;
|
||||
|
||||
m_processIdString.append(output);
|
||||
int cut = m_processIdString.indexOf('\n');
|
||||
if (cut != -1) {
|
||||
m_processId = m_processIdString.left(cut).toLongLong();
|
||||
output = m_processIdString.mid(cut + 1);
|
||||
m_processIdString.clear();
|
||||
return output;
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
qint64 LinuxDeviceProcess::processId() const
|
||||
{
|
||||
return m_processId;
|
||||
}
|
||||
|
||||
QString LinuxDeviceProcess::fullCommandLine(const StandardRunnable &runnable) const
|
||||
{
|
||||
const Environment env = runnable.environment;
|
||||
@@ -66,10 +91,10 @@ QString LinuxDeviceProcess::fullCommandLine(const StandardRunnable &runnable) co
|
||||
envString.append(it.key()).append(QLatin1String("='")).append(it.value())
|
||||
.append(QLatin1Char('\''));
|
||||
}
|
||||
fullCommandLine.append("echo $$ && ");
|
||||
if (!envString.isEmpty())
|
||||
fullCommandLine.append(QLatin1Char(' ')).append(envString);
|
||||
if (!fullCommandLine.isEmpty())
|
||||
fullCommandLine += QLatin1Char(' ');
|
||||
fullCommandLine.append(envString);
|
||||
fullCommandLine.append(" exec ");
|
||||
fullCommandLine.append(quote(runnable.executable));
|
||||
if (!runnable.commandLineArguments.isEmpty()) {
|
||||
fullCommandLine.append(QLatin1Char(' '));
|
||||
|
||||
Reference in New Issue
Block a user