RemoteLinux: Don't rely on the presence of pkill.

Change-Id: Iad42c1c356d9c3914e46082decc0a38d844ed98d
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Christian Kandeler
2011-11-08 17:23:00 +01:00
parent cf1f5b95b3
commit 68f86a9479
4 changed files with 12 additions and 36 deletions

View File

@@ -450,6 +450,17 @@ void AbstractRemoteLinuxApplicationRunner::handlePostRunCleanupDone()
emit error(tr("Error running remote process: %1").arg(d->runner->errorString()));
}
QString AbstractRemoteLinuxApplicationRunner::killApplicationCommandLine() const
{
return QString::fromLocal8Bit("cd /proc; for pid in `ls -d [0123456789]*`; "
"do "
"if [ \"`readlink /proc/$pid/exe`\" = \"%1\" ]; then "
" kill $pid; sleep 1; kill -9 $pid; "
"fi; "
"done").arg(remoteExecutable());
}
const qint64 AbstractRemoteLinuxApplicationRunner::InvalidExitCode = std::numeric_limits<qint64>::min();
@@ -488,18 +499,5 @@ void GenericRemoteLinuxApplicationRunner::doAdditionalConnectionErrorHandling()
{
}
QString GenericRemoteLinuxApplicationRunner::killApplicationCommandLine() const
{
// Prevent pkill from matching our own pkill call.
QString pkillArg = remoteExecutable();
const int lastPos = pkillArg.count() - 1;
pkillArg.replace(lastPos, 1, QLatin1Char('[') + pkillArg.at(lastPos) + QLatin1Char(']'));
const char * const killTemplate = "pkill -%2 -f %1";
const QString niceKill = QString::fromLocal8Bit(killTemplate).arg(pkillArg).arg("SIGTERM");
const QString brutalKill = QString::fromLocal8Bit(killTemplate).arg(pkillArg).arg("SIGKILL");
return niceKill + QLatin1String("; sleep 1; ") + brutalKill;
}
} // namespace RemoteLinux