Fix listen_sockets overflow in close_network_connections()
[tinc] / src / net.c
index 7efe7fa..dd86cf2 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -35,6 +35,7 @@
 #include "protocol.h"
 #include "subnet.h"
 #include "utils.h"
+#include "watchdog.h"
 
 int contradicting_add_edge = 0;
 int contradicting_del_edge = 0;
@@ -160,7 +161,7 @@ void terminate_connection(connection_t *c, bool report) {
                do_outgoing_connection(outgoing);
        }
 
-#ifndef HAVE_MINGW
+#ifndef HAVE_WINDOWS
        /* Clean up dead proxy processes */
 
        while(waitpid(-1, NULL, WNOHANG) > 0);
@@ -195,6 +196,9 @@ static void timeout_handler(void *data) {
                 by default
        */
        if(sleep_time > 2 * udp_discovery_timeout) {
+#ifdef HAVE_WATCHDOG
+               watchdog_ping();
+#endif
                logger(DEBUG_ALWAYS, LOG_ERR, "Awaking from dead after %ld seconds of sleep", sleep_time);
                /*
                        Do not send any packets to tinc after we wake up.
@@ -269,9 +273,7 @@ static void periodic_handler(void *data) {
 
        if(contradicting_del_edge > 100 && contradicting_add_edge > 100) {
                logger(DEBUG_ALWAYS, LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", sleeptime);
-               nanosleep(&(struct timespec) {
-                       sleeptime, 0
-               }, NULL);
+               sleep_millis(sleeptime * 1000);
                sleeptime *= 2;
 
                if(sleeptime < 0) {
@@ -310,7 +312,7 @@ void handle_meta_connection_data(connection_t *c) {
        }
 }
 
-#ifndef HAVE_MINGW
+#ifndef HAVE_WINDOWS
 static void sigterm_handler(void *data) {
        logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s signal", strsignal(((signal_t *)data)->signum));
        event_exit();
@@ -489,7 +491,7 @@ int main_loop(void) {
                0, 0
        });
 
-#ifndef HAVE_MINGW
+#ifndef HAVE_WINDOWS
        signal_t sighup = {0};
        signal_t sigterm = {0};
        signal_t sigquit = {0};
@@ -508,7 +510,7 @@ int main_loop(void) {
                return 1;
        }
 
-#ifndef HAVE_MINGW
+#ifndef HAVE_WINDOWS
        signal_del(&sighup);
        signal_del(&sigterm);
        signal_del(&sigquit);