X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ftincd.c;h=ee3ca1c5a90088c6a350272b6dd9b6e57a7b0756;hp=98dea2542390827e2549798a2029efa8bb54738b;hb=5193a14ddea4c20ffc708dc629a2f91f1e4ccea3;hpb=f08fc359a0b7f638e73a8f866119b016b7dff8de diff --git a/src/tincd.c b/src/tincd.c index 98dea254..ee3ca1c5 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10.4.80 2003/08/02 20:50:38 guus Exp $ + $Id: tincd.c,v 1.10.4.83 2003/08/03 09:55:20 guus Exp $ */ #include "system.h" @@ -41,6 +41,7 @@ #include #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "netutl.h" @@ -78,7 +79,7 @@ char *pidfilename = NULL; /* pid file location */ char *logfilename = NULL; /* log file location */ char **g_argv; /* a copy of the cmdline arguments */ -int exitstatus = 0; +static int status; static struct option const long_options[] = { {"config", required_argument, NULL, 'c'}, @@ -451,23 +452,10 @@ int main2(int argc, char **argv) if(!detach()) return 1; - for(;;) { - if(setup_network_connections()) { - int status; - status = main_loop(); - close_network_connections(); - - ifdebug(CONNECTIONS) - dump_device_stats(); - - logger(LOG_NOTICE, _("Terminating")); - return status; - } - - logger(LOG_ERR, _("Unrecoverable error")); - cp_trace(); + /* Setup sockets and open device. If it doesn't work, don't give up but try again. */ + while(!setup_network_connections()) { if(do_detach) { logger(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout); sleep(maxtimeout); @@ -476,4 +464,18 @@ int main2(int argc, char **argv) return 1; } } + + /* Start main loop. It only exits when tinc is killed. */ + + status = main_loop(); + + /* Shutdown properly. */ + + close_network_connections(); + + ifdebug(CONNECTIONS) + dump_device_stats(); + + logger(LOG_NOTICE, _("Terminating")); + return status; }