Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 12, 2024
1 parent cb06b70 commit e3420da
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
20 changes: 15 additions & 5 deletions ww/managers/signal_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

static signal_manager_t *state = NULL;

void registerAtExitCallback(SignalHandler handle)
void registerAtExitCallback(SignalHandler handle, void *userdata)
{
assert(state != NULL);
assert(state->handlers_len < kMaxSigHandles);
state->handlers[state->handlers_len++] = handle;
state->handlers[state->handlers_len++] = (signal_handler_t) {.handle = handle, .userdata = userdata};
}

signal_manager_t *createSignalManager(void)
Expand Down Expand Up @@ -52,7 +52,7 @@ static void multiplexedSignalHandler(int signum)

for (unsigned int i = 0; i < state->handlers_len; i++)
{
state->handlers[i](signum);
state->handlers[i].handle(state->handlers[i].userdata, signum);
}

if (state->raise_defaults)
Expand All @@ -61,6 +61,15 @@ static void multiplexedSignalHandler(int signum)
}
}

static void multiplexedSignalHandlerNoArg(void)
{

for (unsigned int i = 0; i < state->handlers_len; i++)
{
state->handlers[i].handle(state->handlers[i].userdata, 0);
}
}

void startSignalManager(void)
{
assert(state != NULL);
Expand All @@ -80,7 +89,7 @@ void startSignalManager(void)
exit(1);
}
}

#ifndef OS_WIN

if (state->handle_sigquit)
Expand Down Expand Up @@ -162,6 +171,7 @@ void startSignalManager(void)
exit(1);
}
}

#endif

atexit(multiplexedSignalHandlerNoArg);
}
38 changes: 22 additions & 16 deletions ww/managers/signal_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

#include "ww.h"

typedef void (*SignalHandler)(int signum);
typedef void (*SignalHandler)(void*userdata,int signum);

typedef struct
{
SignalHandler handle;
void *userdata;
} signal_handler_t;

enum
{
Expand All @@ -11,25 +17,25 @@ enum

typedef struct signal_manager_s
{
SignalHandler handlers[kMaxSigHandles];
unsigned int handlers_len;
bool started;
bool raise_defaults;
bool handle_sigint;
bool handle_sigquit;
bool handle_sighup;
bool handle_sigill;
bool handle_sigfpe;
bool handle_sigabrt;
bool handle_sigsegv;
bool handle_sigterm;
bool handle_sigpipe;
bool handle_sigalrm;
signal_handler_t handlers[kMaxSigHandles];
unsigned int handlers_len;
bool started;
bool raise_defaults;
bool handle_sigint;
bool handle_sigquit;
bool handle_sighup;
bool handle_sigill;
bool handle_sigfpe;
bool handle_sigabrt;
bool handle_sigsegv;
bool handle_sigterm;
bool handle_sigpipe;
bool handle_sigalrm;

} signal_manager_t;

signal_manager_t *createSignalManager(void);
signal_manager_t *getSignalManager(void);
void registerAtExitCallback(SignalHandler handle);
void registerAtExitCallback(SignalHandler handle, void *userdata);
void setSignalManager(signal_manager_t *sm);
void startSignalManager(void);
5 changes: 3 additions & 2 deletions ww/managers/socket_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ static bool resetIptables(bool safe_mode)
return result;
}

static void exitHook(int _)
static void exitHook(void *userdata, int _)
{
(void) (userdata);
(void) _;
if (state->iptables_used)
{
Expand Down Expand Up @@ -1008,7 +1009,7 @@ socket_manager_state_t *createSocketManager(void)

#endif

registerAtExitCallback(exitHook);
registerAtExitCallback(exitHook, NULL);

return state;
}

0 comments on commit e3420da

Please sign in to comment.