win: fix ESRCH implementation (#4301)

Per documentation, this was the wrong way to test for ESRCH. This hopefully
fixes it.

Fixes: https://github.com/libuv/libuv/issues/4300
This commit is contained in:
Jameson Nash 2024-02-05 15:24:07 -05:00 committed by GitHub
parent 3f7191e5c2
commit 129362f356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1307,7 +1307,6 @@ static int uv__kill(HANDLE process_handle, int signum) {
case SIGINT: {
/* Unconditionally terminate the process. On Windows, killed processes
* normally return 1. */
DWORD status;
int err;
if (TerminateProcess(process_handle, 1))
@ -1317,8 +1316,7 @@ static int uv__kill(HANDLE process_handle, int signum) {
* TerminateProcess will fail with ERROR_ACCESS_DENIED. */
err = GetLastError();
if (err == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) &&
status != STILL_ACTIVE) {
WaitForSingleObject(process_handle, 0) == WAIT_OBJECT_0) {
return UV_ESRCH;
}
@ -1327,15 +1325,16 @@ static int uv__kill(HANDLE process_handle, int signum) {
case 0: {
/* Health check: is the process still alive? */
DWORD status;
if (!GetExitCodeProcess(process_handle, &status))
return uv_translate_sys_error(GetLastError());
if (status != STILL_ACTIVE)
return UV_ESRCH;
return 0;
switch (WaitForSingleObject(process_handle, 0)) {
case WAIT_OBJECT_0:
return UV_ESRCH;
case WAIT_FAILED:
return uv_translate_sys_error(GetLastError());
case WAIT_TIMEOUT:
return 0;
default:
return UV_UNKNOWN;
}
}
default:
@ -1370,7 +1369,7 @@ int uv_kill(int pid, int signum) {
if (pid == 0) {
process_handle = GetCurrentProcess();
} else {
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
FALSE,
pid);
}