Tweak Window system-exec, wait for process to terminate

This commit is contained in:
Robin Gareus 2023-04-05 00:15:47 +02:00
parent d09c049fee
commit 0b8d5d3dc5
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
1 changed files with 11 additions and 5 deletions

View File

@ -407,15 +407,21 @@ SystemExec::terminate ()
close_stdin();
if (pid) {
/* terminate */
EnumWindows(my_terminateApp, (LPARAM)pid->dwProcessId);
PostThreadMessage(pid->dwThreadId, WM_CLOSE, 0, 0);
/* close windows (if any) */
EnumWindows (my_terminateApp, (LPARAM)pid->dwProcessId);
if (PostThreadMessage (pid->dwThreadId, WM_CLOSE, 0, 0)) {
/* OK, wait for child to terminate cleanly */
WaitForSingleObject(pid->hProcess, 150 /*ms*/);
}
/* kill ! */
TerminateProcess(pid->hProcess, 0xf291);
TerminateProcess(pid->hProcess, 0);
wait ();
CloseHandle(pid->hThread);
CloseHandle(pid->hProcess);
CloseHandle(pid->hThread);
pid->hThread = pid->hProcess = 0;
destroy_pipe(stdinP);
destroy_pipe(stdoutP);
destroy_pipe(stderrP);