- if(do_detach) {
- logger(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
- sleep(maxtimeout);
- } else {
- logger(LOG_ERR, _("Not restarting."));
- exit(1);
- }
- }
+ if(!setup_network_connections())
+ goto end;
+
+ /* Start main loop. It only exits when tinc is killed. */
+
+ status = main_loop();
+
+ /* Shutdown properly. */
+
+ close_network_connections();
+
+ ifdebug(CONNECTIONS)
+ dump_device_stats();
+
+end:
+ logger(LOG_NOTICE, _("Terminating"));
+
+#ifndef HAVE_MINGW
+ remove_pid(pidfilename);
+#endif
+
+ if (identname) free(identname);
+ if (netname) free(netname);
+ if (pidfilename) free(pidfilename);
+ if (logfilename) free(logfilename);
+ if (myport) free(myport);
+ if (device) free(device);
+ if (confbase) free(confbase);
+
+ EVP_cleanup();
+ ENGINE_cleanup();
+ CRYPTO_cleanup_all_ex_data();
+ ERR_remove_state(0);
+ ERR_free_strings();
+
+ return status;