Commit 5d4e9066 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

ios: cleaner kill of subprocess of iostoolhandler



try to first terminate (sig TERM) the tool before
killing it (this ensures a cleaner shutdown of the
connection to the device).

Task-number: QTCREATORBUG-10922
Change-Id: Ib39fbd1d35a651cdb51364532bdef5b69cb1347e
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent fccffba0
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <QScopedArrayPointer> #include <QScopedArrayPointer>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QFileInfo> #include <QFileInfo>
#include <QTimer>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
...@@ -149,12 +150,14 @@ public: ...@@ -149,12 +150,14 @@ public:
void subprocessError(QProcess::ProcessError error); void subprocessError(QProcess::ProcessError error);
void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus); void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void subprocessHasData(); void subprocessHasData();
void killProcess();
virtual bool expectsFileDescriptor() = 0; virtual bool expectsFileDescriptor() = 0;
protected: protected:
void processXml(); void processXml();
IosToolHandler *q; IosToolHandler *q;
QProcess process; QProcess process;
QTimer killTimer;
QXmlStreamReader outputParser; QXmlStreamReader outputParser;
QString deviceId; QString deviceId;
QString bundlePath; QString bundlePath;
...@@ -200,6 +203,7 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, ...@@ -200,6 +203,7 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType,
q(q), state(NonStarted), devType(devType), iBegin(0), iEnd(0), q(q), state(NonStarted), devType(devType), iBegin(0), iEnd(0),
gdbSocket(-1) gdbSocket(-1)
{ {
killTimer.setSingleShot(true);
QProcessEnvironment env(QProcessEnvironment::systemEnvironment()); QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
foreach (const QString &k, env.keys()) foreach (const QString &k, env.keys())
if (k.startsWith(QLatin1String("DYLD_"))) if (k.startsWith(QLatin1String("DYLD_")))
...@@ -219,6 +223,8 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, ...@@ -219,6 +223,8 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType,
q, SLOT(subprocessFinished(int,QProcess::ExitStatus))); q, SLOT(subprocessFinished(int,QProcess::ExitStatus)));
QObject::connect(&process, SIGNAL(error(QProcess::ProcessError)), QObject::connect(&process, SIGNAL(error(QProcess::ProcessError)),
q, SLOT(subprocessError(QProcess::ProcessError))); q, SLOT(subprocessError(QProcess::ProcessError)));
QObject::connect(&killTimer, SIGNAL(timeout()),
q, SLOT(killProcess()));
} }
bool IosToolHandlerPrivate::isRunning() bool IosToolHandlerPrivate::isRunning()
...@@ -268,8 +274,10 @@ void IosToolHandlerPrivate::stop(int errorCode) ...@@ -268,8 +274,10 @@ void IosToolHandlerPrivate::stop(int errorCode)
case Stopped: case Stopped:
return; return;
} }
if (process.state() != QProcess::NotRunning) if (process.state() != QProcess::NotRunning) {
process.kill(); process.terminate();
killTimer.start(1500);
}
} }
// signals // signals
...@@ -341,6 +349,7 @@ void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatu ...@@ -341,6 +349,7 @@ void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatu
stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 ); stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 );
if (debugToolHandler) if (debugToolHandler)
qDebug() << "IosToolHandler::finished(" << this << ")"; qDebug() << "IosToolHandler::finished(" << this << ")";
killTimer.stop();
emit q->finished(q); emit q->finished(q);
} }
...@@ -693,6 +702,12 @@ void IosSimulatorToolHandlerPrivate::addDeviceArguments(QStringList &args) const ...@@ -693,6 +702,12 @@ void IosSimulatorToolHandlerPrivate::addDeviceArguments(QStringList &args) const
} }
} }
void IosToolHandlerPrivate::killProcess()
{
if (process.state() != QProcess::NotRunning)
process.kill();
}
} // namespace Internal } // namespace Internal
QString IosToolHandler::iosDeviceToolPath() QString IosToolHandler::iosDeviceToolPath()
...@@ -763,4 +778,9 @@ void IosToolHandler::subprocessHasData() ...@@ -763,4 +778,9 @@ void IosToolHandler::subprocessHasData()
d->subprocessHasData(); d->subprocessHasData();
} }
void IosToolHandler::killProcess()
{
d->killProcess();
}
} // namespace Ios } // namespace Ios
...@@ -99,6 +99,7 @@ private slots: ...@@ -99,6 +99,7 @@ private slots:
void subprocessError(QProcess::ProcessError error); void subprocessError(QProcess::ProcessError error);
void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus); void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void subprocessHasData(); void subprocessHasData();
void killProcess();
private: private:
friend class Ios::Internal::IosToolHandlerPrivate; friend class Ios::Internal::IosToolHandlerPrivate;
Ios::Internal::IosToolHandlerPrivate *d; Ios::Internal::IosToolHandlerPrivate *d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment