diff options
author | Maurice Kalinowski <maurice.kalinowski@theqtcompany.com> | 2015-12-08 11:42:24 +0100 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@theqtcompany.com> | 2015-12-09 12:41:27 +0000 |
commit | 0ea3d630b1fd1fc21c65c43063792e4cbf0c2cdf (patch) | |
tree | 60c37644e9821a051bd786a8644ffec8f4c3f29a /src/winmain | |
parent | 7d2c87311e682eabc9b7a3b1e1b4e2f21d0623bf (diff) | |
download | qtbase-0ea3d630b1fd1fc21c65c43063792e4cbf0c2cdf.tar.gz |
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 <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src/winmain')
-rw-r--r-- | src/winmain/qtmain_winrt.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
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<LPCVOID>(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<LPCWSTR>(pidFileName.utf16()), - 0, FILE_SHARE_READ|FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms); + pidFile = CreateFile2(reinterpret_cast<LPCWSTR>(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<char *> args; HANDLE mainThread; + HANDLE pidFile; }; // Main entry point for Appx containers |