Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: uv_kill() should report UV_ESRC when the victim is already dead

  • Loading branch information...
piscisaureus committed Jun 12, 2012
1 parent 048422d commit b7e150ee917c07509515e1a7051fd8336c8f3e57
Showing with 36 additions and 22 deletions.
  1. +36 −22 src/win/process.c
@@ -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);
}
}


0 comments on commit b7e150e

Please sign in to comment.
You can’t perform that action at this time.