summaryrefslogtreecommitdiff
path: root/src/fdevent_win32.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2023-01-28 08:14:02 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2023-05-03 23:11:34 -0400
commitc6f021b2ecceb513068a6577df6b365038052bb0 (patch)
tree74a2add359befbae7864be42ddb19badaf25246e /src/fdevent_win32.c
parente3c97fc2c227560becf41a7d0fdb6007deb3b38c (diff)
downloadlighttpd-git-c6f021b2ecceb513068a6577df6b365038052bb0.tar.gz
[core] _WIN32 fdevent_kill()
Diffstat (limited to 'src/fdevent_win32.c')
-rw-r--r--src/fdevent_win32.c29
1 files changed, 28 insertions, 1 deletions
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)
{