Browse Source

* merge signal handlers

master
Alex 'AdUser' Z 9 years ago
parent
commit
c6370906be
  1. 29
      src/main.c

29
src/main.c

@ -33,15 +33,20 @@ struct {
enum { stop = 0, run, reconfig, test } state = run; enum { stop = 0, run, reconfig, test } state = run;
void sa_term(int signum) { void signal_handler(int signum) {
UNUSED(signum); switch (signum) {
f2b_log_msg(log_info, "got SIGTERM/SIGINT, exiting"); case SIGTERM:
state = stop; case SIGINT:
} f2b_log_msg(log_info, "got SIGTERM/SIGINT, exiting");
void sa_hup(int signum) { state = stop;
UNUSED(signum); break;
f2b_log_msg(log_note, "got SIGHUP, reloading config"); case SIGHUP:
state = reconfig; f2b_log_msg(log_note, "got SIGHUP, reloading config");
state = reconfig;
break;
default:
break;
}
} }
#define SA_REGISTER(SIGNUM, HANDLER) \ #define SA_REGISTER(SIGNUM, HANDLER) \
@ -139,9 +144,9 @@ int main(int argc, char *argv[]) {
} }
} }
SA_REGISTER(SIGTERM, &sa_term); SA_REGISTER(SIGTERM, &signal_handler);
SA_REGISTER(SIGINT, &sa_term); SA_REGISTER(SIGINT, &signal_handler);
SA_REGISTER(SIGHUP, &sa_hup); SA_REGISTER(SIGHUP, &signal_handler);
if (opts.config_path[0] == '\0') if (opts.config_path[0] == '\0')
usage(EXIT_FAILURE); usage(EXIT_FAILURE);

Loading…
Cancel
Save