{
}
+void sighup_handler(int signal, short events, void *data) {
+ connection_t *c;
+ avl_node_t *node;
+ char *fname;
+ struct stat s;
+ static time_t last_config_check = 0;
+
+ /* Reread our own configuration file */
+
+ exit_configuration(&config_tree);
+ init_configuration(&config_tree);
+
+ if(!read_server_config()) {
+ logger(LOG_ERR, _("Unable to reread configuration file, exitting."));
+ event_loopexit(NULL);
+ return;
+ }
+
+ /* Close connections to hosts that have a changed or deleted host config file */
+
+ for(node = connection_tree->head; node; node = node->next) {
+ c = node->data;
+
+ if(c->outgoing) {
+ free(c->outgoing->name);
+ if(c->outgoing->ai)
+ freeaddrinfo(c->outgoing->ai);
+ free(c->outgoing);
+ c->outgoing = NULL;
+ }
+
+ asprintf(&fname, "%s/hosts/%s", confbase, c->name);
+ if(stat(fname, &s) || s.st_mtime > last_config_check)
+ terminate_connection(c, c->status.active);
+ free(fname);
+ }
+
+ last_config_check = time(NULL);
+
+ /* Try to make outgoing connections */
+
+ try_outgoing_connections();
+}
+
/*
this is where it all happens...
*/
{
struct timeval tv;
int r;
- time_t last_ping_check, last_config_check;
+ time_t last_ping_check;
tevent_t *event;
struct event timeout;
+ struct event sighup_event;
cp();
+ signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
+ signal_add(&sighup_event, NULL);
+
last_ping_check = now;
- last_config_check = now;
srand(now);
sigalrm = false;
}
- if(sighup) {
- connection_t *c;
- avl_node_t *node;
- char *fname;
- struct stat s;
-
- sighup = false;
-
- /* Reread our own configuration file */
-
- exit_configuration(&config_tree);
- init_configuration(&config_tree);
-
- if(!read_server_config()) {
- logger(LOG_ERR, _("Unable to reread configuration file, exitting."));
- return 1;
- }
-
- /* Close connections to hosts that have a changed or deleted host config file */
-
- for(node = connection_tree->head; node; node = node->next) {
- c = node->data;
-
- if(c->outgoing) {
- free(c->outgoing->name);
- if(c->outgoing->ai)
- freeaddrinfo(c->outgoing->ai);
- free(c->outgoing);
- c->outgoing = NULL;
- }
-
- asprintf(&fname, "%s/hosts/%s", confbase, c->name);
- if(stat(fname, &s) || s.st_mtime > last_config_check)
- terminate_connection(c, c->status.active);
- free(fname);
- }
-
- last_config_check = now;
-
- /* Try to make outgoing connections */
-
- try_outgoing_connections();
- }
}
+ signal_del(&sighup_event);
+
return 0;
}
/* If zero, don't detach from the terminal. */
bool do_detach = true;
-bool sighup = false;
bool sigalrm = false;
extern char *identname;
}
}
-static RETSIGTYPE sighup_handler(int a)
-{
- logger(LOG_NOTICE, _("Got %s signal"), "HUP");
- sighup = true;
-}
-
static RETSIGTYPE sigint_handler(int a)
{
logger(LOG_NOTICE, _("Got %s signal"), "INT");
int signal;
void (*handler)(int);
} sighandlers[] = {
- {SIGHUP, sighup_handler},
{SIGTERM, sigterm_handler},
{SIGQUIT, sigquit_handler},
{SIGSEGV, fatal_signal_handler},
/* If we didn't detach, allow coredumps */
if(!do_detach)
- sighandlers[3].handler = SIG_DFL;
+ sighandlers[2].handler = SIG_DFL;
/* Then, for each known signal that we want to catch, assign a
handler to the signal, with error checking this time. */