diff options
author | Robert Griebl <robert.griebl@qt.io> | 2020-02-06 21:00:17 +0100 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2020-02-10 12:30:23 +0100 |
commit | 202319498b3f9a6d1d7f2e189eb9388687198d0d (patch) | |
tree | 40d1dbb253599d12abacc7f530cacaa23594eefe | |
parent | 51ef3d423b53299c04552ae7eff864dff4470d87 (diff) |
Make sure to kill any child processes when the main AM process crashes (II)
This adds a Windows version to the already existing Unix mechanism.
Change-Id: I7d92699875730322507d19a26cce794918caf267
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r-- | src/common-lib/crashhandler.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common-lib/crashhandler.cpp b/src/common-lib/crashhandler.cpp index 1b24d3a4..185311eb 100644 --- a/src/common-lib/crashhandler.cpp +++ b/src/common-lib/crashhandler.cpp @@ -59,6 +59,31 @@ void CrashHandler::setQmlEngine(QQmlEngine *engine) QT_END_NAMESPACE_AM +#if defined(Q_OS_WINDOWS) + +#include <Windows.h> + +// this will make the constructor run before all other static constructor functions +# pragma warning(push) +# pragma warning(disable: 4074) +# pragma init_seg(compiler) +static struct InitReaper +{ + InitReaper() + { + // create a "process group", so that child process are automatically killed if this process dies + HANDLE hJob = CreateJobObject(nullptr, nullptr); + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits; + memset(&limits, 0, sizeof(limits)); + limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &limits, sizeof(limits)); + AssignProcessToJobObject(hJob, GetCurrentProcess()); + } +} dummy; +# pragma warning(pop) + +#endif + #else #if defined(QT_QML_LIB) |