Module: wine
Branch: stable
Commit: c5052649f53ff03696d0c417420b26e3ff1d3007
URL: https://gitlab.winehq.org/wine/wine/-/commit/c5052649f53ff03696d0c417420b26…
Author: Eric Pouech <eric.pouech(a)gmail.com>
Date: Tue Jan 25 08:31:34 2022 +0100
start: Wrap child inside a job so it gets killed when start.exe terminates.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50869
Signed-off-by: Eric Pouech <eric.pouech(a)gmail.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit a1abb524fee5b033e761d700b87353f14b009680)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/start/start.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/programs/start/start.c b/programs/start/start.c
index dcd0a113f59..b5bf8187603 100644
--- a/programs/start/start.c
+++ b/programs/start/start.c
@@ -676,7 +676,24 @@ done:
if (sei.fMask & SEE_MASK_NOCLOSEPROCESS) {
DWORD exitcode;
+ HANDLE hJob;
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
+
SetConsoleCtrlHandler(NULL, TRUE);
+ hJob = CreateJobObjectA(NULL, NULL);
+ /* Create a job where the child is associated... if the start.exe terminates
+ * before the child, the job will be terminated, and the child will be terminated as well.
+ * (The idea is to allow to kill (from a Unix standpoint) a created Windows
+ * process (here start.exe), and that the unix-kill of start.exe will be also terminate
+ * start.exe's child process).
+ */
+ memset(&info, 0, sizeof(info));
+ info.BasicLimitInformation.LimitFlags =
+ JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE |
+ JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK;
+ SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &info, sizeof(info));
+ AssignProcessToJobObject(hJob, sei.hProcess);
+
WaitForSingleObject(sei.hProcess, INFINITE);
GetExitCodeProcess(sei.hProcess, &exitcode);
ExitProcess(exitcode);