diff options
author | Bartosz Sosnowski <bartosz@janeasystems.com> | 2017-11-21 14:35:36 +0100 |
---|---|---|
committer | Bartosz Sosnowski <bartosz@janeasystems.com> | 2017-12-07 14:00:05 +0100 |
commit | 890eedaf59cea75faaa6a14b4248a472dcadb831 (patch) | |
tree | 6ab91056fe1f79048f74063ceaa77d9ea7c3b679 /src | |
parent | c73e73c8743cc664460a8ae173f034481d94323f (diff) | |
download | libuv-890eedaf59cea75faaa6a14b4248a472dcadb831.tar.gz libuv-890eedaf59cea75faaa6a14b4248a472dcadb831.zip |
win, process: uv_kill improvements
Maps pid 0 to the current process, simulating Linux kill sending signal
to the process group.
Adds detection of invalid signals. If the signum is invalid - below 0
or NSIG or above – UV_EINVAL will be returned instead of UV_ENOSYS.
PR-URL: https://github.com/libuv/libuv/pull/1642
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/win/process.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/win/process.c b/src/win/process.c index 764250e1..cc06d9e2 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -1173,6 +1173,10 @@ int uv_spawn(uv_loop_t* loop, static int uv__kill(HANDLE process_handle, int signum) { + if (signum < 0 || signum >= NSIG) { + return UV_EINVAL; + } + switch (signum) { case SIGTERM: case SIGKILL: @@ -1237,8 +1241,15 @@ int uv_process_kill(uv_process_t* process, int signum) { int uv_kill(int pid, int signum) { int err; - HANDLE process_handle = OpenProcess(PROCESS_TERMINATE | - PROCESS_QUERY_INFORMATION, FALSE, pid); + HANDLE process_handle; + + if (pid == 0) { + process_handle = GetCurrentProcess(); + } else { + process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, + FALSE, + pid); + } if (process_handle == NULL) { err = GetLastError(); |