Call event_init() after detaching.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 21 Jul 2012 12:19:23 +0000 (14:19 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 21 Jul 2012 12:19:23 +0000 (14:19 +0200)
Otherwise, the call to daemon() could close filedescriptors in use by libevent
itself; for example if it uses kqueue or epoll instead of a select() or poll()
backend.

src/tincd.c

index 3cbac4ba25f5daa4a29b2f0189dc8b466aff035a..9f65bbeacf8f85d54c6221c41756649d70714d92 100644 (file)
@@ -382,11 +382,6 @@ int main(int argc, char **argv) {
 
        openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
 
-       if(!event_init()) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "Error initializing libevent!");
-               return 1;
-       }
-
        g_argv = argv;
 
        if(getenv("LISTEN_PID") && atoi(getenv("LISTEN_PID")) == getpid())
@@ -439,6 +434,11 @@ int main2(int argc, char **argv) {
        }
 #endif
 
+       if(!event_init()) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Error initializing libevent!");
+               return 1;
+       }
+
        /* Setup sockets and open device. */
 
        if(!setup_network())