From 0489adf0cb9f101b0d7b28fc28c477f115482a4e Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Thu, 28 Nov 2013 14:58:31 +0100 Subject: iostoolhandler: thighten stop process gurantee that finished is emitted also when the process fails to start and always after the sub process has actually finished. Change-Id: I716ebf62074dc77790716e60e88348a932cbe9f6 Reviewed-by: Oswald Buddenhagen Reviewed-by: Fawzi Mohamed --- src/plugins/ios/iostoolhandler.cpp | 120 +++++++++++++++---------------------- 1 file changed, 48 insertions(+), 72 deletions(-) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index 5a6eaf6491..c1984f2275 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -129,7 +129,7 @@ public: virtual void requestDeviceInfo(const QString &deviceId, int timeout = 1000) = 0; bool isRunning(); void start(const QString &exe, const QStringList &args); - void stop(); + void stop(int errorCode); // signals void isTransferringApp(const QString &bundlePath, const QString &deviceId, int progress, @@ -226,20 +226,40 @@ void IosToolHandlerPrivate::start(const QString &exe, const QStringList &args) state = StartedInferior; } -void IosToolHandlerPrivate::stop() +void IosToolHandlerPrivate::stop(int errorCode) { if (debugToolHandler) qDebug() << "IosToolHandlerPrivate::stop"; - if (process.state() != QProcess::NotRunning) { - process.close(); - process.kill(); - if (debugToolHandler) - qDebug() << "killing"; - } - if (state != Stopped) { - state = Stopped; - emit q->finished(q); + State oldState = state; + state = Stopped; + switch (oldState) { + case NonStarted: + qDebug() << "IosToolHandler::stop() when state was NonStarted"; + // pass + case Starting: + switch (op){ + case OpNone: + qDebug() << "IosToolHandler::stop() when op was OpNone"; + break; + case OpAppTransfer: + didTransferApp(bundlePath, deviceId, IosToolHandler::Failure); + break; + case OpAppRun: + didStartApp(bundlePath, deviceId, IosToolHandler::Failure); + break; + case OpDeviceInfo: + break; + } + // pass + case StartedInferior: + case XmlEndProcessed: + toolExited(errorCode); + break; + case Stopped: + return; } + if (process.state() != QProcess::NotRunning) + process.kill(); } // signals @@ -296,67 +316,22 @@ void IosToolHandlerPrivate::toolExited(int code) void IosToolHandlerPrivate::subprocessError(QProcess::ProcessError error) { - switch (state) { - case NonStarted: - qDebug() << "subprocessError() when state was NonStarted"; - // pass - case Starting: - switch (op){ - case OpNone: - qDebug() << "subprocessError() when op is OpNone"; - break; - case OpAppTransfer: - didTransferApp(bundlePath, deviceId, IosToolHandler::Failure); - break; - case OpAppRun: - didStartApp(bundlePath, deviceId, IosToolHandler::Failure); - break; - case OpDeviceInfo: - break; - } - // pass - case StartedInferior: - errorMsg(IosToolHandler::tr("Subprocess Error %1").arg(error)); - toolExited(-1); - break; - case XmlEndProcessed: - case Stopped: - qDebug() << "IosToolHandler, subprocessError() in an already stopped process"; + if (state != Stopped) + errorMsg(IosToolHandler::tr("iOS tool Error %1").arg(error)); + stop(-1); + if (error == QProcess::FailedToStart) { + if (debugToolHandler) + qDebug() << "IosToolHandler::finished(" << this << ")"; + emit q->finished(q); } } void IosToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus) { - // process potentially pending data - subprocessHasData(); - switch (state) { - case NonStarted: - qDebug() << "subprocessFinished() when state was NonStarted"; - // pass - case Starting: - switch (op){ - case OpNone: - qDebug() << "subprocessFinished() when op was OpNone"; - break; - case OpAppTransfer: - didTransferApp(bundlePath, deviceId, IosToolHandler::Failure); - break; - case OpAppRun: - didStartApp(bundlePath, deviceId, IosToolHandler::Failure); - break; - case OpDeviceInfo: - break; - } - // pass - case StartedInferior: - case XmlEndProcessed: - toolExited((exitStatus == QProcess::CrashExit && exitCode == 0) ? -1 : exitCode); - break; - case Stopped: - if (debugToolHandler) - qDebug() << "IosToolHandler, subprocessFinished() in an already stopped process (normal)"; - break; - } + stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 ); + if (debugToolHandler) + qDebug() << "IosToolHandler::finished(" << this << ")"; + emit q->finished(q); } void IosToolHandlerPrivate::processXml() @@ -469,7 +444,8 @@ void IosToolHandlerPrivate::processXml() break; case ParserState::QueryResult: state = XmlEndProcessed; - break; + stop(0); + return; case ParserState::AppOutput: break; case ParserState::AppStarted: @@ -523,7 +499,7 @@ void IosToolHandlerPrivate::processXml() if (outputParser.hasError() && outputParser.error() != QXmlStreamReader::PrematureEndOfDocumentError) { qDebug() << "error parsing iosTool output:" << outputParser.errorString(); - stop(); + stop(-1); } } @@ -544,7 +520,7 @@ void IosToolHandlerPrivate::subprocessHasData() while (true) { qint64 rRead = process.read(buf, sizeof(buf)); if (rRead == -1) { - stop(); + stop(-1); return; } if (rRead == 0) @@ -556,7 +532,7 @@ void IosToolHandlerPrivate::subprocessHasData() } } case XmlEndProcessed: - stop(); + stop(0); return; case Stopped: return; @@ -737,7 +713,7 @@ IosToolHandler::~IosToolHandler() void IosToolHandler::stop() { - d->stop(); + d->stop(-1); } void IosToolHandler::requestTransferApp(const QString &bundlePath, const QString &deviceId, -- cgit v1.2.1 From d5a8adc1560135a46ff4aac2dbced1a7b4acfbd6 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Fri, 29 Nov 2013 01:20:00 +0100 Subject: ios: ensure that the private dependencies are resolved by dyld Change-Id: I36f493dc83a906fb2291b156488531cfff633d4a Reviewed-by: Fawzi Mohamed --- src/plugins/ios/iostoolhandler.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index c1984f2275..a70d9152a0 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -203,6 +204,12 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, foreach (const QString &k, env.keys()) if (k.startsWith(QLatin1String("DYLD_"))) env.remove(k); + QString xcPath = IosConfigurations::developerPath().appendPath(QLatin1String("../OtherFrameworks")).toFileInfo().canonicalFilePath(); + env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), + xcPath.isEmpty() ? + QLatin1String("/System/Library/PrivateFrameworks") + : (xcPath + QLatin1String(":/System/Library/PrivateFrameworks"))); + process.setProcessEnvironment(env); QObject::connect(&process, SIGNAL(readyReadStandardOutput()), q, SLOT(subprocessHasData())); QObject::connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), -- cgit v1.2.1 From 11037dfcb2d3fb01ec1aefdb624f74966447eba7 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Mon, 2 Dec 2013 12:52:45 +0100 Subject: ios: fix compilation on other platforms fix ternary operator types Change-Id: I4f9a0eb100fd6ca4e65e91ef67a53331d3f8faaa Reviewed-by: Nikita Baryshnikov Reviewed-by: Friedemann Kleint --- src/plugins/ios/iostoolhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index a70d9152a0..d78fd473c7 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -207,7 +207,7 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, QString xcPath = IosConfigurations::developerPath().appendPath(QLatin1String("../OtherFrameworks")).toFileInfo().canonicalFilePath(); env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), xcPath.isEmpty() ? - QLatin1String("/System/Library/PrivateFrameworks") + QString::fromLatin1("/System/Library/PrivateFrameworks") : (xcPath + QLatin1String(":/System/Library/PrivateFrameworks"))); process.setProcessEnvironment(env); -- cgit v1.2.1 From fccffba04bbac0439583272b1c73151e9a00b0c6 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Wed, 4 Dec 2013 12:57:07 +0100 Subject: ios: fixing DYLD_FALLBACK_FRAMEWORK_PATH adding /System/Library/Frameworks for completeness Change-Id: If2fbe015af591eb3ff820b2ea2f732b2d4c08e01 Reviewed-by: Fawzi Mohamed --- src/plugins/ios/iostoolhandler.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index d78fd473c7..bda73d5bab 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -204,12 +204,15 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, foreach (const QString &k, env.keys()) if (k.startsWith(QLatin1String("DYLD_"))) env.remove(k); + QStringList frameworkPaths; QString xcPath = IosConfigurations::developerPath().appendPath(QLatin1String("../OtherFrameworks")).toFileInfo().canonicalFilePath(); - env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), - xcPath.isEmpty() ? - QString::fromLatin1("/System/Library/PrivateFrameworks") - : (xcPath + QLatin1String(":/System/Library/PrivateFrameworks"))); - + if (!xcPath.isEmpty()) + frameworkPaths << xcPath; + frameworkPaths << QLatin1String("/System/Library/Frameworks") + << QLatin1String("/System/Library/PrivateFrameworks"); + env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), frameworkPaths.join(QLatin1Char(':'))); + if (debugToolHandler) + qDebug() << "IosToolHandler runEnv:" << env.toStringList(); process.setProcessEnvironment(env); QObject::connect(&process, SIGNAL(readyReadStandardOutput()), q, SLOT(subprocessHasData())); QObject::connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), -- cgit v1.2.1 From 5d4e9066c8c53f2612f809b5f6d28b0c39561ec1 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Wed, 4 Dec 2013 12:58:29 +0100 Subject: 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 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index bda73d5bab..8431331952 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 -- cgit v1.2.1 From 9206fefb6ba0952cdc4927ae8b7962e870e1fb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 4 Dec 2013 22:41:42 +0100 Subject: Fix build failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QStringList::join doesn't accept a QLatin1Char on my system. This fixes a build regression introduced in commit fccffba04bbac0439583272b1c73151e9a00b0c6. Change-Id: I98d8339032cb5ea315e09860aac3db91ab21d4c5 Reviewed-by: André Hartmann Reviewed-by: Orgad Shaneh Reviewed-by: Eike Ziller --- src/plugins/ios/iostoolhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/ios/iostoolhandler.cpp') diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp index 8431331952..cc921ae41e 100644 --- a/src/plugins/ios/iostoolhandler.cpp +++ b/src/plugins/ios/iostoolhandler.cpp @@ -214,7 +214,7 @@ IosToolHandlerPrivate::IosToolHandlerPrivate(IosToolHandler::DeviceType devType, frameworkPaths << xcPath; frameworkPaths << QLatin1String("/System/Library/Frameworks") << QLatin1String("/System/Library/PrivateFrameworks"); - env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), frameworkPaths.join(QLatin1Char(':'))); + env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), frameworkPaths.join(QLatin1String(":"))); if (debugToolHandler) qDebug() << "IosToolHandler runEnv:" << env.toStringList(); process.setProcessEnvironment(env); -- cgit v1.2.1