Skip to content

Commit

Permalink
patch SIGKILL for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Feb 2, 2025
1 parent fb9316d commit 4c0262a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4760,6 +4760,11 @@ Patches for Windows


***************************************************************************** */
#ifndef SIGKILL
#ifdef SIGABRT
#define SIGKILL SIGABRT
#endif
#endif
#if FIO_OS_WIN

/* *****************************************************************************
Expand Down Expand Up @@ -7652,7 +7657,8 @@ Windows Implementation

static struct {
int32_t sig;
volatile unsigned flag;
uint16_t propagate;
volatile uint16_t flag;
void (*callback)(int sig, void *);
void *udata;
void (*old)(int sig);
Expand Down Expand Up @@ -7731,22 +7737,22 @@ SFUNC int fio_signal_forget(int sig) {
fio___signal_watchers[i].callback = NULL;
fio___signal_watchers[i].udata = (void *)1;
fio___signal_watchers[i].sig = 0;
if (fio___signal_watchers[i].old.sa_handler &&
fio___signal_watchers[i].old.sa_handler != SIG_DFL) {
if (fio___signal_watchers[i].old &&
fio___signal_watchers[i].old != SIG_DFL) {
if ((intptr_t)signal(sig, fio___signal_watchers[i].old) ==
(intptr_t)SIG_ERR)
goto sig_error;
} else {
if ((intptr_t)signal(sig, SIG_DFL) == (intptr_t)SIG_ERR)
goto sig_error;
}
fio___signal_watchers[i].old.sa_handler = SIG_DFL;
fio___signal_watchers[i].old = SIG_DFL;
return 0;
}
signal(sig, SIG_DFL);
return -1;
sig_error:
fio___signal_watchers[i].old.sa_handler = SIG_DFL;
fio___signal_watchers[i].old = SIG_DFL;
signal(sig, SIG_DFL);
FIO_LOG_ERROR("couldn't unset signal handler: %s", strerror(errno));
return -1;
Expand Down Expand Up @@ -36945,13 +36951,16 @@ The IO Reactor Cycle (the actual work)
static void fio___io_signal_crash(int sig, void *flg) {
FIO_LOG_FATAL("(%d) additional stop signal(!) - should crash.", FIO___IO.pid);
fio_signal_forget(sig);

#ifdef SIGKILL
/* cannot lock, signal may be received during critical section */
FIO_LIST_EACH(fio___io_pid_s, node, &FIO___IO.pids, pos) {
if (!pos->done)
fio_thread_kill(pos->pid, SIGKILL);
}
fio_thread_kill(FIO___IO.root_pid, SIGKILL);
fio_thread_kill(FIO___IO.pid, SIGKILL);
#endif
exit(-1);
(void)sig, (void)flg;
}
Expand Down
5 changes: 5 additions & 0 deletions fio-stl/001 patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Patches for Windows
***************************************************************************** */
#ifndef SIGKILL
#ifdef SIGABRT
#define SIGKILL SIGABRT
#endif
#endif
#if FIO_OS_WIN

/* *****************************************************************************
Expand Down
11 changes: 6 additions & 5 deletions fio-stl/002 signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ Windows Implementation

static struct {
int32_t sig;
volatile unsigned flag;
uint16_t propagate;
volatile uint16_t flag;
void (*callback)(int sig, void *);
void *udata;
void (*old)(int sig);
Expand Down Expand Up @@ -251,22 +252,22 @@ SFUNC int fio_signal_forget(int sig) {
fio___signal_watchers[i].callback = NULL;
fio___signal_watchers[i].udata = (void *)1;
fio___signal_watchers[i].sig = 0;
if (fio___signal_watchers[i].old.sa_handler &&
fio___signal_watchers[i].old.sa_handler != SIG_DFL) {
if (fio___signal_watchers[i].old &&
fio___signal_watchers[i].old != SIG_DFL) {
if ((intptr_t)signal(sig, fio___signal_watchers[i].old) ==
(intptr_t)SIG_ERR)
goto sig_error;
} else {
if ((intptr_t)signal(sig, SIG_DFL) == (intptr_t)SIG_ERR)
goto sig_error;
}
fio___signal_watchers[i].old.sa_handler = SIG_DFL;
fio___signal_watchers[i].old = SIG_DFL;
return 0;
}
signal(sig, SIG_DFL);
return -1;
sig_error:
fio___signal_watchers[i].old.sa_handler = SIG_DFL;
fio___signal_watchers[i].old = SIG_DFL;
signal(sig, SIG_DFL);
FIO_LOG_ERROR("couldn't unset signal handler: %s", strerror(errno));
return -1;
Expand Down
3 changes: 3 additions & 0 deletions fio-stl/402 io reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ The IO Reactor Cycle (the actual work)
static void fio___io_signal_crash(int sig, void *flg) {
FIO_LOG_FATAL("(%d) additional stop signal(!) - should crash.", FIO___IO.pid);
fio_signal_forget(sig);

#ifdef SIGKILL
/* cannot lock, signal may be received during critical section */
FIO_LIST_EACH(fio___io_pid_s, node, &FIO___IO.pids, pos) {
if (!pos->done)
fio_thread_kill(pos->pid, SIGKILL);
}
fio_thread_kill(FIO___IO.root_pid, SIGKILL);
fio_thread_kill(FIO___IO.pid, SIGKILL);
#endif
exit(-1);
(void)sig, (void)flg;
}
Expand Down

0 comments on commit 4c0262a

Please sign in to comment.