This repository has been archived by the owner on May 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Igor Zinkovsky
committed
Nov 2, 2011
1 parent
8d5c64a
commit 31f94db
Showing
5 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,11 @@ | |
#include <stdio.h> | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <signal.h> | ||
#include <windows.h> | ||
|
||
#define SIGKILL 9 | ||
|
||
typedef struct env_var { | ||
const char* narrow; | ||
const wchar_t* wide; | ||
|
@@ -1052,35 +1055,65 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, | |
} | ||
|
||
|
||
int uv_process_kill(uv_process_t* process, int signum) { | ||
static uv_err_t uv__kill(HANDLE process_handle, int signum) { | ||
DWORD status; | ||
uv_err_t err; | ||
|
||
if (signum == SIGTERM || signum == SIGKILL) { | ||
/* Kill the process. On Windows, killed processes normally return 1. */ | ||
if (TerminateProcess(process_handle, 1)) { | ||
return uv_ok_; | ||
} else { | ||
return uv__new_sys_error(GetLastError()); | ||
} | ||
} else if (signum == 0) { | ||
/* Health check: is the process still alive? */ | ||
if (GetExitCodeProcess(process_handle, &status) && | ||
status == STILL_ACTIVE) { | ||
return uv_ok_; | ||
} else { | ||
err.code = UV_EINVAL; | ||
This comment has been minimized.
Sorry, something went wrong.
piscisaureus
|
||
return err; | ||
} | ||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return uv_ok_; | ||
} | ||
|
||
|
||
int uv_process_kill(uv_process_t* process, int signum) { | ||
uv_err_t err; | ||
|
||
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; | ||
} | ||
err = uv__kill(process->process_handle, signum); | ||
|
||
if (err.code != UV_OK) { | ||
uv__set_error(process->loop, err.code, err.sys_errno_); | ||
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; | ||
} | ||
|
||
process->exit_signal = signum; | ||
|
||
return 0; | ||
} | ||
|
||
|
||
uv_err_t uv_kill(int pid, int signum) { | ||
uv_err_t err; | ||
HANDLE process_handle = OpenProcess(PROCESS_TERMINATE | | ||
PROCESS_QUERY_INFORMATION, FALSE, pid); | ||
|
||
if (process_handle == INVALID_HANDLE_VALUE) { | ||
err.code = UV_EINVAL; | ||
This comment has been minimized.
Sorry, something went wrong.
piscisaureus
|
||
return err; | ||
} | ||
|
||
assert(0 && "unreachable"); | ||
err = uv__kill(process_handle, signum); | ||
CloseHandle(process_handle); | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uv_ok_
is defined insrc/win/error.c
andsrc/unix/dl.c
. Probably It should be moved tosrc/common.c
and an extern added tocommon.h
?