- struct event sighup_event;
- struct event sigterm_event;
- struct event sigquit_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(&sigterm_event, SIGTERM, sigterm_handler, NULL);
- signal_add(&sigterm_event, NULL);
- signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL);
- signal_add(&sigquit_event, NULL);
-
- if(event_loop(0) < 0) {
- logger(LOG_ERR, _("Error while waiting for input: %s"), strerror(errno));
- return 1;
+
+ timeout_event.time = time(NULL) + pingtimeout;
+ timeout_event.handler = timeout_handler;
+ timeout_event.data = &timeout_event;
+
+ event_add(&timeout_event);
+
+
+ while(true) {
+ mutex_unlock(&mutex);
+ usleep(1000000);
+ mutex_lock(&mutex);
+
+ struct event *event;
+ while((event = get_expired_event())) {
+ event->handler(event->data);
+ }