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

Commit

Permalink
windows: uv_kill() should report UV_ESRC when the victim is already dead
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 12, 2012
1 parent 048422d commit b7e150e
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/win/process.c
Expand Up @@ -1320,32 +1320,46 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,


static uv_err_t uv__kill(HANDLE process_handle, int signum) {
DWORD status;
uv_err_t err;
switch (signum) {
case SIGTERM:
case SIGKILL:
case SIGINT: {
/* Unconditionally terminate the process. On Windows, killed processes */
/* normally return 1. */
DWORD error, status;

if (TerminateProcess(process_handle, 1))
return uv_ok_;

/* If the process already exited before TerminateProcess was called, */
/* TerminateProcess will fail with ERROR_ACESS_DENIED. */
error = GetLastError();
if (error == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) &&
status != STILL_ACTIVE) {
return uv__new_artificial_error(UV_ESRCH);
}

if (signum == SIGTERM || signum == SIGKILL || signum == SIGINT) {
/* Kill the process. On Windows, killed processes normally return 1. */
if (TerminateProcess(process_handle, 1)) {
err = uv_ok_;
} else {
err = uv__new_sys_error(GetLastError());
return uv__new_sys_error(error);
}
} else if (signum == 0) {
/* Health check: is the process still alive? */
if (GetExitCodeProcess(process_handle, &status)) {
if (status == STILL_ACTIVE) {
err = uv_ok_;
} else {
err = uv__new_artificial_error(UV_ESRCH);
}
} else {
err = uv__new_sys_error(GetLastError());

case 0: {
/* Health check: is the process still alive? */
DWORD status;

if (!GetExitCodeProcess(process_handle, &status))
return uv__new_sys_error(GetLastError());

if (status != STILL_ACTIVE)
return uv__new_artificial_error(UV_ESRCH);

return uv_ok_;
}
} else {
err = uv__new_artificial_error(UV_ENOSYS);
}

return err;
default:
/* Unsupported signal. */
return uv__new_artificial_error(UV_ENOSYS);
}
}


Expand Down

0 comments on commit b7e150e

Please sign in to comment.