X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ftincd.c;h=0536d96f5c32c5a2355809d68360836023efbdf8;hp=fcd705227cde3266a5bbdf51543979933af871e4;hb=85adeef21275633b78a234b2660cbe3bc9dd2c33;hpb=4dde583bc91985c3ff19ac1d1f1bc791b50658ff diff --git a/src/tincd.c b/src/tincd.c index fcd70522..0536d96f 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.9 2000/09/06 11:49:05 guus Exp $ + $Id: tincd.c,v 1.10.4.12 2000/10/15 00:59:37 guus Exp $ */ #include "config.h" @@ -63,10 +63,7 @@ static int kill_tincd = 0; /* If zero, don't detach from the terminal. */ static int do_detach = 1; -char *confbase = NULL; /* directory in which all config files are */ -/* char *configfilename = NULL; /* configuration file name, moved to config.c */ char *identname; /* program name for syslog */ -char *netname = NULL; /* name of the vpn network */ char *pidfilename; /* pid file location */ static pid_t ppid; /* pid of non-detached part */ char **g_argv; /* a copy of the cmdline arguments */ @@ -98,7 +95,7 @@ usage(int status) else { printf(_("Usage: %s [option]...\n\n"), program_name); - printf(_(" -c, --config=FILE Read configuration options from FILE.\n" + printf(_(" -c, --config=DIR Read configuration options from DIR.\n" " -D, --no-detach Don't fork and detach.\n" " -d Increase debug level.\n" " -k, --kill Attempt to kill a running tincd and exit.\n" @@ -125,8 +122,8 @@ parse_options(int argc, char **argv, char **envp) case 0: /* long option */ break; case 'c': /* config file */ - configfilename = xmalloc(strlen(optarg)+1); - strcpy(configfilename, optarg); + confbase = xmalloc(strlen(optarg)+1); + strcpy(confbase, optarg); break; case 'D': /* no detach */ do_detach = 0; @@ -182,7 +179,7 @@ int detach(void) if(pid) /* parent process */ { signal(SIGTERM, parent_exit); - sleep(600); /* wait 10 minutes */ +// sleep(600); /* wait 10 minutes */ exit(1); } } @@ -293,29 +290,24 @@ int kill_other(void) */ void make_names(void) { - if(!configfilename) - { - if(netname) - { - asprintf(&configfilename, "%s/tinc/%s/tinc.conf", CONFDIR, netname); - } - else - { - asprintf(&configfilename, "%s/tinc/tinc.conf", CONFDIR); - } - } - if(netname) { - asprintf(&pidfilename, "/var/run/tinc.%s.pid", netname); - asprintf(&confbase, "%s/tinc/%s/", CONFDIR, netname); - asprintf(&identname, "tinc.%s", netname); + if(!pidfilename) + asprintf(&pidfilename, "/var/run/tinc.%s.pid", netname); + if(!confbase) + asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname); + if(!identname) + asprintf(&identname, "tinc.%s", netname); } else { - pidfilename = "/var/run/tinc.pid"; - asprintf(&confbase, "%s/tinc/", CONFDIR); - identname = "tinc"; + netname = "bla"; + if(!pidfilename) + pidfilename = "/var/run/tinc.pid"; + if(!confbase) + asprintf(&confbase, "%s/tinc", CONFDIR); + if(!identname) + identname = "tinc"; } } @@ -328,17 +320,20 @@ main(int argc, char **argv, char **envp) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + /* Do some intl stuff right now */ + + unknown = _("unknown"); + parse_options(argc, argv, envp); if(show_version) { printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE, VERSION, __DATE__, __TIME__, PROT_CURRENT); - printf(_("Copyright (C) 1998,1999,2000 Ivo Timmermans and others,\n" - "see the AUTHORS file for a complete list.\n\n" + printf(_("Copyright (C) 1998,1999,2000 Ivo Timmermans, Guus Sliepen and others.\n" + "See the AUTHORS file for a complete list.\n\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to redistribute it under certain conditions;\n" - "see the file COPYING for details.\n\n")); - printf(_("This product includes software developed by Eric Young (eay@mincom.oz.au)\n")); + "see the file COPYING for details.\n")); return 0; } @@ -359,7 +354,7 @@ main(int argc, char **argv, char **envp) if(kill_tincd) exit(kill_other()); - if(read_config_file(configfilename)) + if(read_server_config()) return 1; setup_signals(); @@ -367,19 +362,31 @@ main(int argc, char **argv, char **envp) if(detach()) exit(0); +/* FIXME: wt* is this suppose to do? if(security_init()) return 1; - +*/ for(;;) { - setup_network_connections(); - - main_loop(); - - cleanup_and_exit(1); - - syslog(LOG_ERR, _("Unrecoverable error, restarting in %d seconds!"), MAXTIMEOUT); - sleep(MAXTIMEOUT); + if(!setup_network_connections()) + { + main_loop(); + cleanup_and_exit(1); + } + + syslog(LOG_ERR, _("Unrecoverable error")); + cp_trace(); + + if(do_detach) + { + syslog(LOG_NOTICE, _("Restarting in %d seconds!"), MAXTIMEOUT); + sleep(MAXTIMEOUT); + } + else + { + syslog(LOG_ERR, _("Aieee! Not restarting.")); + exit(0); + } } } @@ -402,23 +409,30 @@ sigquit_handler(int a) RETSIGTYPE sigsegv_square(int a) { - syslog(LOG_NOTICE, _("Got another SEGV signal: not restarting")); + syslog(LOG_ERR, _("Got another SEGV signal: not restarting")); exit(0); } RETSIGTYPE sigsegv_handler(int a) { - if(cp_file) - syslog(LOG_NOTICE, _("Got SEGV signal after %s line %d, trying to re-execute"), - cp_file, cp_line); - else - syslog(LOG_NOTICE, _("Got SEGV signal, trying to re-execute")); + syslog(LOG_ERR, _("Got SEGV signal")); + cp_trace(); - signal(SIGSEGV, sigsegv_square); - close_network_connections(); - remove_pid(pidfilename); - execvp(g_argv[0], g_argv); + if(do_detach) + { + syslog(LOG_NOTICE, _("Trying to re-execute in 5 seconds...")); + signal(SIGSEGV, sigsegv_square); + close_network_connections(); + sleep(5); + remove_pid(pidfilename); + execvp(g_argv[0], g_argv); + } + else + { + syslog(LOG_NOTICE, _("Aieee! Not restarting.")); + exit(0); + } } RETSIGTYPE @@ -448,17 +462,16 @@ sigusr2_handler(int a) { if(debug_lvl > 1) syslog(LOG_NOTICE, _("Got USR2 signal, forcing new key generation")); +/* FIXME: reprogram this. regenerate_keys(); +*/ } RETSIGTYPE sighuh(int a) { - if(cp_file) - syslog(LOG_NOTICE, _("Got unexpected %s after %s line %d"), - strsignal(a), cp_file, cp_line); - else - syslog(LOG_NOTICE, _("Got unexpected %s"), strsignal(a)); + syslog(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a)); + cp_trace(); } void