#include <sys/time.h>
#include <signal.h>
-int newserv_shutdown_pending;
-int newserv_sigusr1_pending;
-
void initseed();
void init_logfile();
void siginthandler(int sig);
void sigusr1handler(int sig);
+void sigsegvhandler(int sig);
+void sighuphandler(int sig);
+void handlecore(void);
+void handlesignals(void);
+
+int newserv_shutdown_pending;
+static int newserv_sigusr1_pending, newserv_sighup_pending;
+static void (*oldsegv)(int);
int main(int argc, char **argv) {
initseed();
initmodules();
signal(SIGINT, siginthandler);
signal(SIGUSR1, sigusr1handler);
+ signal(SIGHUP, sighuphandler);
+ oldsegv = signal(SIGSEGV, sigsegvhandler);
/* Main loop */
for(;;) {
handleevents(10);
doscheduledevents(time(NULL));
+
if (newserv_shutdown_pending) {
newserv_shutdown();
break;
}
- if (newserv_sigusr1_pending) {
- triggerhook(HOOK_CORE_SIGUSR1, NULL);
- newserv_sigusr1_pending=0;
- }
+ handlesignals();
}
nsexit();
finisstring();
}
+void handlesignals(void) {
+ if (newserv_sigusr1_pending) {
+ signal(SIGUSR1, sigusr1handler);
+ Error("core", ERR_INFO, "SIGUSR1 received.");
+ triggerhook(HOOK_CORE_SIGUSR1, NULL);
+ newserv_sigusr1_pending=0;
+ }
+
+ if (newserv_sighup_pending) {
+ signal(SIGHUP, sigusr1handler);
+ Error("core", ERR_INFO, "SIGHUP received, rehashing...");
+ triggerhook(HOOK_CORE_REHASH, (void *)1);
+ newserv_sighup_pending=0;
+ }
+}
+
/*
* seed the pseudo-random number generator, rand()
*/
void sigusr1handler(int sig) {
newserv_sigusr1_pending = 1;
}
+
+void sighuphandler(int sig) {
+ newserv_sighup_pending = 1;
+}
+
+void sigsegvhandler(int sig) {
+ handlecore();
+
+ oldsegv(sig);
+}