From 0ea3d630b1fd1fc21c65c43063792e4cbf0c2cdf Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 8 Dec 2015 11:42:24 +0100 Subject: winrt: Store exit code in pid file We have to call Exit() to successfully close an application as done in 25dcc90d799fba3e3f0391783ed07cb22cd1115a. Unfortunately Exit() always sets the exit code to 1 and this cannot be changed programmatically. Hence write the exit code into the pid file which is created when launched via winrtrunner. winrtrunner then fetches the content and passes the exit code to its callee. This implies that the pidFile is not deleted by the app itself anymore. Task-number: QTBUG-38654 Change-Id: Ib9b6ae4a0d61c9bf7e530e984aae3ad6204c39a0 Reviewed-by: Oliver Wolff --- src/winmain/qtmain_winrt.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/winmain/qtmain_winrt.cpp b/src/winmain/qtmain_winrt.cpp index 473c41ab8e..5d2abcccc7 100644 --- a/src/winmain/qtmain_winrt.cpp +++ b/src/winmain/qtmain_winrt.cpp @@ -140,6 +140,8 @@ public: hr = applicationFactory->CreateInstance(this, &base, &core); RETURN_VOID_IF_FAILED("Failed to create application container instance"); + + pidFile = INVALID_HANDLE_VALUE; } ~AppContainer() @@ -157,6 +159,13 @@ public: int argc = app->args.count(); char **argv = app->args.data(); const int res = main(argc, argv); + if (app->pidFile != INVALID_HANDLE_VALUE) { + const QByteArray resString = QByteArray::number(res); + WriteFile(app->pidFile, reinterpret_cast(resString.constData()), + resString.size(), NULL, NULL); + FlushFileBuffers(app->pidFile); + CloseHandle(app->pidFile); + } app->core->Exit(); return res; }, this, CREATE_SUSPENDED, nullptr); @@ -248,11 +257,10 @@ private: .absoluteFilePath(QString::number(uint(GetCurrentProcessId())) + QStringLiteral(".pid")); CREATEFILE2_EXTENDED_PARAMETERS params = { sizeof(CREATEFILE2_EXTENDED_PARAMETERS), - FILE_ATTRIBUTE_NORMAL, FILE_FLAG_DELETE_ON_CLOSE + FILE_ATTRIBUTE_NORMAL }; - // (Unused) handle will automatically be closed when the app exits - CreateFile2(reinterpret_cast(pidFileName.utf16()), - 0, FILE_SHARE_READ|FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms); + pidFile = CreateFile2(reinterpret_cast(pidFileName.utf16()), + GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, 0); // Install the develMode message handler #ifndef Q_OS_WINPHONE defaultMessageHandler = qInstallMessageHandler(devMessageHandler); @@ -315,6 +323,7 @@ private: QByteArray commandLine; QVarLengthArray args; HANDLE mainThread; + HANDLE pidFile; }; // Main entry point for Appx containers -- cgit v1.2.3