diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2023-01-28 08:14:02 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-03 23:11:34 -0400 |
commit | c6f021b2ecceb513068a6577df6b365038052bb0 (patch) | |
tree | 74a2add359befbae7864be42ddb19badaf25246e /src | |
parent | e3c97fc2c227560becf41a7d0fdb6007deb3b38c (diff) | |
download | lighttpd-git-c6f021b2ecceb513068a6577df6b365038052bb0.tar.gz |
[core] _WIN32 fdevent_kill()
Diffstat (limited to 'src')
-rw-r--r-- | src/fdevent.c | 7 | ||||
-rw-r--r-- | src/fdevent.h | 1 | ||||
-rw-r--r-- | src/fdevent_win32.c | 29 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/fdevent.c b/src/fdevent.c index 67a7ea60..43d2622e 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -431,7 +431,7 @@ int fdevent_set_stdin_stdout_stderr(int fdin, int fdout, int fderr) { #include <stdio.h> /* perror() rename() */ -#include <signal.h> /* signal() */ +#include <signal.h> /* signal() kill() */ int fdevent_rename(const char *oldpath, const char *newpath) { @@ -497,6 +497,11 @@ pid_t fdevent_fork_execve(const char *name, char *argv[], char *envp[], int fdin } +int fdevent_kill (pid_t pid, int sig) { + return kill(pid, sig); +} + + #include "sys-wait.h" int fdevent_waitpid(pid_t pid, int * const status, int nb) { diff --git a/src/fdevent.h b/src/fdevent.h index 8ee741b3..9364eb4f 100644 --- a/src/fdevent.h +++ b/src/fdevent.h @@ -118,6 +118,7 @@ pid_t fdevent_fork_execve(const char *name, char *argv[], char *envp[], int fdin #endif int fdevent_waitpid(pid_t pid, int *status, int nb); int fdevent_waitpid_intr(pid_t pid, int *status); +int fdevent_kill(pid_t pid, int sig); #ifdef _WIN32 __attribute_cold__ diff --git a/src/fdevent_win32.c b/src/fdevent_win32.c index 5dc20ce2..00b37cb0 100644 --- a/src/fdevent_win32.c +++ b/src/fdevent_win32.c @@ -330,7 +330,11 @@ int fdevent_fcntl_set_nb_cloexec_sock (int fd) #include <windows.h> -#include <signal.h> /* sig_atomic_t */ +#include <signal.h> /* sig_atomic_t SIGKILL */ + +#ifndef SIGKILL +#define SIGKILL 9 +#endif #ifndef INFINITE #define INFINITE 0xFFFFFFFF @@ -377,6 +381,29 @@ void fdevent_win32_cleanup (void) } +int fdevent_kill (pid_t pid, int sig) +{ + /* fdevent_createprocess() uses CREATE_NEW_PROCESS_GROUP flag */ + if (sig != SIGKILL) + return GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid) ? 0 : -1; + + /* note: not thread-safe; not efficient with many processes (O(n)) */ + struct pilist *pi; + struct pilist **next = &pilist; + while ((pi = *next) && pid != pi->pid) + next = &pi->next; + if (pi) + return TerminateProcess(pi->hProcess, SIGKILL) ? 0 : -1; + + HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (!hProcess) + return -1; + int rc = TerminateProcess(hProcess, SIGKILL) ? 0 : -1;/*(SIGKILL ExitCode)*/ + CloseHandle(hProcess); + return rc; +} + + int fdevent_waitpid (pid_t pid, int * const status, int nb) { |