From 5d4e9066c8c53f2612f809b5f6d28b0c39561ec1 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Wed, 4 Dec 2013 12:58:29 +0100 Subject: [PATCH] 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: Fawzi Mohamed --- src/plugins/ios/iostoolhandler.cpp | 24 ++++++++++++++++++++++-- src/plugins/ios/iostoolhandler.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index bda73d5babc..84313319528 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -149,12 +150,14 @@ public: void subprocessError(QProcess::ProcessError error); void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus); void subprocessHasData(); + void killProcess(); virtual bool expectsFileDescriptor() = 0; protected: void processXml(); IosToolHandler *q; QProcess process; + QTimer killTimer; QXmlStreamReader outputParser; QString deviceId; QString bundlePath; @@ -200,6 +203,7 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, q(q), state(NonStarted), devType(devType), iBegin(0), iEnd(0), gdbSocket(-1) { + killTimer.setSingleShot(true); QProcessEnvironment env(QProcessEnvironment::systemEnvironment()); foreach (const QString &k, env.keys()) if (k.startsWith(QLatin1String("DYLD_"))) @@ -219,6 +223,8 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, q, SLOT(subprocessFinished(int,QProcess::ExitStatus))); QObject::connect(&process, SIGNAL(error(QProcess::ProcessError)), q, SLOT(subprocessError(QProcess::ProcessError))); + QObject::connect(&killTimer, SIGNAL(timeout()), + q, SLOT(killProcess())); } bool IosToolHandlerPrivate::isRunning() @@ -268,8 +274,10 @@ void IosToolHandlerPrivate::stop(int errorCode) case Stopped: return; } - if (process.state() != QProcess::NotRunning) - process.kill(); + if (process.state() != QProcess::NotRunning) { + process.terminate(); + killTimer.start(1500); + } } // signals @@ -341,6 +349,7 @@ void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatu stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 ); if (debugToolHandler) qDebug() << "IosToolHandler::finished(" << this << ")"; + killTimer.stop(); emit q->finished(q); } @@ -693,6 +702,12 @@ void IosSimulatorToolHandlerPrivate::addDeviceArguments(QStringList &args) const } } +void IosToolHandlerPrivate::killProcess() +{ + if (process.state() != QProcess::NotRunning) + process.kill(); +} + } // namespace Internal QString IosToolHandler::iosDeviceToolPath() @@ -763,4 +778,9 @@ void IosToolHandler::subprocessHasData() d->subprocessHasData(); } +void IosToolHandler::killProcess() +{ + d->killProcess(); +} + } // namespace Ios diff --git a/src/plugins/ios/iostoolhandler.h b/src/plugins/ios/iostoolhandler.h index 11c4a56e751..de8e53c4845 100644 --- a/src/plugins/ios/iostoolhandler.h +++ b/src/plugins/ios/iostoolhandler.h @@ -99,6 +99,7 @@ private slots: void subprocessError(QProcess::ProcessError error); void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus); void subprocessHasData(); + void killProcess(); private: friend class Ios::Internal::IosToolHandlerPrivate; Ios::Internal::IosToolHandlerPrivate *d;