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>
This commit is contained in:
parent
c73e73c874
commit
890eedaf59
@ -1173,6 +1173,10 @@ int uv_spawn(uv_loop_t* loop,
|
|||||||
|
|
||||||
|
|
||||||
static int uv__kill(HANDLE process_handle, int signum) {
|
static int uv__kill(HANDLE process_handle, int signum) {
|
||||||
|
if (signum < 0 || signum >= NSIG) {
|
||||||
|
return UV_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
case SIGKILL:
|
case SIGKILL:
|
||||||
@ -1237,8 +1241,15 @@ int uv_process_kill(uv_process_t* process, int signum) {
|
|||||||
|
|
||||||
int uv_kill(int pid, int signum) {
|
int uv_kill(int pid, int signum) {
|
||||||
int err;
|
int err;
|
||||||
HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |
|
HANDLE process_handle;
|
||||||
PROCESS_QUERY_INFORMATION, FALSE, pid);
|
|
||||||
|
if (pid == 0) {
|
||||||
|
process_handle = GetCurrentProcess();
|
||||||
|
} else {
|
||||||
|
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
|
||||||
|
FALSE,
|
||||||
|
pid);
|
||||||
|
}
|
||||||
|
|
||||||
if (process_handle == NULL) {
|
if (process_handle == NULL) {
|
||||||
err = GetLastError();
|
err = GetLastError();
|
||||||
|
|||||||
@ -266,6 +266,7 @@ TEST_DECLARE (spawn_tcp_server)
|
|||||||
TEST_DECLARE (fs_poll)
|
TEST_DECLARE (fs_poll)
|
||||||
TEST_DECLARE (fs_poll_getpath)
|
TEST_DECLARE (fs_poll_getpath)
|
||||||
TEST_DECLARE (kill)
|
TEST_DECLARE (kill)
|
||||||
|
TEST_DECLARE (kill_invalid_signum)
|
||||||
TEST_DECLARE (fs_file_noent)
|
TEST_DECLARE (fs_file_noent)
|
||||||
TEST_DECLARE (fs_file_nametoolong)
|
TEST_DECLARE (fs_file_nametoolong)
|
||||||
TEST_DECLARE (fs_file_loop)
|
TEST_DECLARE (fs_file_loop)
|
||||||
@ -756,6 +757,7 @@ TASK_LIST_START
|
|||||||
TEST_ENTRY (fs_poll)
|
TEST_ENTRY (fs_poll)
|
||||||
TEST_ENTRY (fs_poll_getpath)
|
TEST_ENTRY (fs_poll_getpath)
|
||||||
TEST_ENTRY (kill)
|
TEST_ENTRY (kill)
|
||||||
|
TEST_ENTRY (kill_invalid_signum)
|
||||||
|
|
||||||
TEST_ENTRY (poll_close_doesnt_corrupt_stack)
|
TEST_ENTRY (poll_close_doesnt_corrupt_stack)
|
||||||
TEST_ENTRY (poll_closesocket)
|
TEST_ENTRY (poll_closesocket)
|
||||||
|
|||||||
@ -22,6 +22,26 @@
|
|||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEST_IMPL(kill_invalid_signum) {
|
||||||
|
uv_pid_t pid;
|
||||||
|
|
||||||
|
pid = uv_os_getpid();
|
||||||
|
|
||||||
|
ASSERT(uv_kill(pid, -1) == UV_EINVAL);
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* NSIG is not available on all platforms. */
|
||||||
|
ASSERT(uv_kill(pid, NSIG) == UV_EINVAL);
|
||||||
|
#endif
|
||||||
|
ASSERT(uv_kill(pid, 4096) == UV_EINVAL);
|
||||||
|
|
||||||
|
MAKE_VALGRIND_HAPPY();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* For Windows we test only signum handling */
|
/* For Windows we test only signum handling */
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static void signum_test_cb(uv_signal_t* handle, int signum) {
|
static void signum_test_cb(uv_signal_t* handle, int signum) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user