Android: Don't use blocking queued connections for running ps

If ps is run from a different thread than the GUI thread, then we are
obviously not dealing with the "checkPID" function that's running every
second. We don't need to be overly prudent about starting another
process then. On the other hand, the blocking queued connection relies
on the ps shell not getting closed from a different thread in between
and it is generally a risk for creating dead locks.

Change-Id: Ief49fb18cc3199dc345c4d9ca0ee24b66d33343c
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Ulf Hermann
2016-07-27 15:53:46 +02:00
parent 5d34676fdc
commit cbd738ab90
2 changed files with 15 additions and 21 deletions

View File

@@ -251,27 +251,16 @@ static int extractPid(const QString &exeName, const QByteArray &psOutput)
return extractPidFromChunk(psOutput, from);
}
QByteArray AndroidRunner::runPs()
{
if (QThread::currentThread() != thread()) {
QByteArray ret;
QMetaObject::invokeMethod(this, "runPs", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QByteArray, ret));
return ret;
} else {
QByteArray psLine("ps");
if (m_isBusyBox)
psLine += " -w";
psLine += '\n';
m_psProc.write(psLine);
m_psProc.waitForBytesWritten(psLine.size());
return m_psProc.readAllStandardOutput();
}
}
void AndroidRunner::checkPID()
{
QByteArray psOut = runPs();
m_processPID = extractPid(m_androidRunnable.packageName, psOut);
// Don't write to m_psProc from a different thread
QTC_ASSERT(QThread::currentThread() == thread(), return);
QByteArray psLine(m_isBusyBox ? "ps -w\n" : "ps\n");
m_psProc.write(psLine);
m_psProc.waitForBytesWritten(psLine.size());
m_processPID = extractPid(m_androidRunnable.packageName, m_psProc.readAllStandardOutput());
if (m_processPID == -1) {
if (m_wasStarted) {
@@ -306,11 +295,17 @@ void AndroidRunner::checkPID()
void AndroidRunner::forceStop()
{
// Don't run Utils::SynchronousProcess on the GUI thread
QTC_ASSERT(QThread::currentThread() != thread(), return);
runAdb(selector() << _("shell") << _("am") << _("force-stop") << m_androidRunnable.packageName,
nullptr, 30);
// try killing it via kill -9
const QByteArray out = runPs();
const QByteArray out = Utils::SynchronousProcess()
.runBlocking(m_adb, selector() << _("shell") << _(m_isBusyBox ? "ps -w" : "ps"))
.allRawOutput();
int from = 0;
while (1) {
const int to = out.indexOf('\n', from);