- struct timeval tv;
- int r;
- struct event timeout_event;
- struct event sighup_event;
- struct event sigint_event;
- struct event sigterm_event;
- struct event sigquit_event;
- struct event sigusr1_event;
- struct event sigusr2_event;
- struct event sigwinch_event;
- struct event sigalrm_event;
-
- cp();
-
- timeout_set(&timeout_event, timeout_handler, &timeout_event);
- event_add(&timeout_event, &(struct timeval){pingtimeout, 0});
- signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
- signal_add(&sighup_event, NULL);
- signal_set(&sigint_event, SIGINT, sigint_handler, NULL);
- signal_add(&sigint_event, NULL);
- signal_set(&sigterm_event, SIGTERM, sigterm_handler, NULL);
- signal_add(&sigterm_event, NULL);
- signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL);
- signal_add(&sigquit_event, NULL);
- signal_set(&sigusr1_event, SIGUSR1, sigusr1_handler, NULL);
- signal_add(&sigusr1_event, NULL);
- signal_set(&sigusr2_event, SIGUSR2, sigusr2_handler, NULL);
- signal_add(&sigusr2_event, NULL);
- signal_set(&sigwinch_event, SIGWINCH, sigwinch_handler, NULL);
- signal_add(&sigwinch_event, NULL);
- signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL);
- signal_add(&sigalrm_event, NULL);
-
- if(event_loop(0) < 0) {
- logger(LOG_ERR, _("Error while waiting for input: %s"), strerror(errno));
+ timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval){pingtimeout, rand() % 100000});
+ timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000});
+
+#ifndef HAVE_MINGW
+ signal_t sighup = {0};
+ signal_t sigterm = {0};
+ signal_t sigquit = {0};
+ signal_t sigint = {0};
+ signal_t sigalrm = {0};
+
+ signal_add(&sighup, sighup_handler, &sighup, SIGHUP);
+ signal_add(&sigterm, sigterm_handler, &sigterm, SIGTERM);
+ signal_add(&sigquit, sigterm_handler, &sigquit, SIGQUIT);
+ signal_add(&sigint, sigterm_handler, &sigint, SIGINT);
+ signal_add(&sigalrm, sigalrm_handler, &sigalrm, SIGALRM);
+#endif
+
+ if(!event_loop()) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno));