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:
Ulf Hermann
2016-04-21 11:49:10 +02:00
parent 8372d2199f
commit 0bef62481b
4 changed files with 49 additions and 6 deletions

View File

@@ -172,6 +172,11 @@ void SshDeviceProcess::setSshServerSupportsSignals(bool signalsSupported)
d->serverSupportsSignals = signalsSupported;
}
qint64 SshDeviceProcess::processId() const
{
return 0;
}
void SshDeviceProcess::handleConnected()
{
QTC_ASSERT(d->state == SshDeviceProcessPrivate::Connecting, return);
@@ -303,8 +308,12 @@ void SshDeviceProcess::SshDeviceProcessPrivate::doSignal(QSsh::SshRemoteProcess:
process->sendSignal(signal);
} else {
DeviceProcessSignalOperation::Ptr signalOperation = q->device()->signalOperation();
quint64 processId = q->processId();
if (signal == QSsh::SshRemoteProcess::IntSignal) {
signalOperation->interruptProcess(runnable.executable);
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;
@@ -312,7 +321,10 @@ void SshDeviceProcess::SshDeviceProcessPrivate::doSignal(QSsh::SshRemoteProcess:
connect(signalOperation.data(), &DeviceProcessSignalOperation::finished, q,
&SshDeviceProcess::handleKillOperationFinished);
killTimer.start(5000);
signalOperation->killProcess(runnable.executable);
if (processId != 0)
signalOperation->killProcess(processId);
else
signalOperation->killProcess(runnable.executable);
}
}
break;