Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
win: make uv_process_kill(proc, 0) report process status
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 11, 2011
1 parent acc98ca commit a3d495c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/win/process.c
Expand Up @@ -1053,13 +1053,34 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,


int uv_process_kill(uv_process_t* process, int signum) {
process->exit_signal = signum;
DWORD status;

/* On windows killed processes normally return 1 */
if (process->process_handle != INVALID_HANDLE_VALUE &&
TerminateProcess(process->process_handle, 1)) {
if (process->process_handle == INVALID_HANDLE_VALUE) {
uv__set_artificial_error(process->loop, UV_EINVAL);
return -1;
}

if (signum) {
/* Kill the process. On Windows, killed processes normally return 1. */
if (TerminateProcess(process->process_handle, 1)) {
process->exit_signal = signum;
return 0;
}
else {
uv__set_sys_error(process->loop, GetLastError());
return -1;
}
}
else {
/* Health check: is the process still alive? */
if (GetExitCodeProcess(process->process_handle, &status) && status == STILL_ACTIVE) {
return 0;
}
else {
uv__set_artificial_error(process->loop, UV_EINVAL);
return -1;
}
}

return -1;
assert(0 && "unreachable");
}

0 comments on commit a3d495c

Please sign in to comment.