winrt: Store exit code in pid file
We have to call Exit() to successfully close an application as done in
25dcc90d79. 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>
bb10
parent
7d2c87311e
commit
0ea3d630b1
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue