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>
This commit is contained in:
Maurice Kalinowski 2015-12-08 11:42:24 +01:00
parent 7d2c87311e
commit 0ea3d630b1

View File

@ -140,6 +140,8 @@ public:
hr = applicationFactory->CreateInstance(this, &base, &core); hr = applicationFactory->CreateInstance(this, &base, &core);
RETURN_VOID_IF_FAILED("Failed to create application container instance"); RETURN_VOID_IF_FAILED("Failed to create application container instance");
pidFile = INVALID_HANDLE_VALUE;
} }
~AppContainer() ~AppContainer()
@ -157,6 +159,13 @@ public:
int argc = app->args.count(); int argc = app->args.count();
char **argv = app->args.data(); char **argv = app->args.data();
const int res = main(argc, argv); 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(); app->core->Exit();
return res; return res;
}, this, CREATE_SUSPENDED, nullptr); }, this, CREATE_SUSPENDED, nullptr);
@ -248,11 +257,10 @@ private:
.absoluteFilePath(QString::number(uint(GetCurrentProcessId())) + QStringLiteral(".pid")); .absoluteFilePath(QString::number(uint(GetCurrentProcessId())) + QStringLiteral(".pid"));
CREATEFILE2_EXTENDED_PARAMETERS params = { CREATEFILE2_EXTENDED_PARAMETERS params = {
sizeof(CREATEFILE2_EXTENDED_PARAMETERS), 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 pidFile = CreateFile2(reinterpret_cast<LPCWSTR>(pidFileName.utf16()),
CreateFile2(reinterpret_cast<LPCWSTR>(pidFileName.utf16()), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, 0);
0, FILE_SHARE_READ|FILE_SHARE_DELETE, CREATE_ALWAYS, &params);
// Install the develMode message handler // Install the develMode message handler
#ifndef Q_OS_WINPHONE #ifndef Q_OS_WINPHONE
defaultMessageHandler = qInstallMessageHandler(devMessageHandler); defaultMessageHandler = qInstallMessageHandler(devMessageHandler);
@ -315,6 +323,7 @@ private:
QByteArray commandLine; QByteArray commandLine;
QVarLengthArray<char *> args; QVarLengthArray<char *> args;
HANDLE mainThread; HANDLE mainThread;
HANDLE pidFile;
}; };
// Main entry point for Appx containers // Main entry point for Appx containers