--- gvpe/src/vped.C 2003/03/01 15:53:03 1.1 +++ gvpe/src/vped.C 2004/01/29 18:55:10 1.15 @@ -2,7 +2,7 @@ vped.C -- the main file for vped Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003 Marc Lehmannn + 2003 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include @@ -33,8 +35,11 @@ #include #include -#include +#if HAVE_SYS_MMAN_H +# include +#endif +#include #include #include "gettext.h" @@ -43,9 +48,10 @@ #include "conf.h" #include "slog.h" #include "util.h" -#include "protocol.h" +#include "vpn.h" +#include "iom.h" -vpn network; +static loglevel llevel = L_NONE; /* If nonzero, display usage information and exit. */ static int show_help; @@ -53,10 +59,8 @@ /* If nonzero, print the version on standard output and exit. */ static int show_version; -#if HAVE_MLOCKALL /* If nonzero, disable swapping for this process. */ static int do_mlock = 0; -#endif /* If zero, don't detach from the terminal. */ static int do_detach = 1; @@ -68,9 +72,7 @@ {"version", no_argument, &show_version, 1}, {"no-detach", no_argument, &do_detach, 0}, {"log-level", required_argument, NULL, 'l'}, -#if HAVE_MLOCKALL {"mlock", no_argument, &do_mlock, 1}, -#endif {NULL, 0, NULL, 0} }; @@ -120,19 +122,15 @@ do_detach = 0; break; -#if HAVE_MLOCKALL case 'L': /* lock into memory */ do_mlock = 1; break; -#endif case 'l': /* inc debug level */ { - loglevel l = string_to_loglevel (optarg); + llevel = string_to_loglevel (optarg); - if (l != L_NONE) - set_loglevel (l); - else + if (llevel == L_NONE) slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); } break; @@ -168,17 +166,20 @@ sigterm_handler (int a) { network.events |= vpn::EVENT_SHUTDOWN; + network.event.start (0); } RETSIGTYPE sighup_handler (int a) { network.events |= vpn::EVENT_RECONNECT; + network.event.start (0); } RETSIGTYPE sigusr1_handler (int a) { + network.dump_status (); } RETSIGTYPE @@ -198,6 +199,7 @@ act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); + act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL); act.sa_flags = SA_RESETHAND; act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); @@ -206,6 +208,8 @@ int main (int argc, char **argv, char **envp) { + ERR_load_crypto_strings (); // we have the RAM + set_loglevel (L_INFO); set_identity (argv[0]); log_to (LOGTO_SYSLOG | LOGTO_STDERR); @@ -218,8 +222,9 @@ if (show_version) { - printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), + printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); + printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); printf (_ ("Copyright (C) 2003 Marc Lehmann and others.\n" "See the AUTHORS file for a complete list.\n\n" @@ -237,7 +242,7 @@ /* Lock all pages into memory if requested */ -#if HAVE_MLOCKALL +#if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK if (do_mlock) if (mlockall (MCL_CURRENT | MCL_FUTURE)) slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); @@ -246,29 +251,29 @@ make_names (); conf.read_config (true); - RAND_load_file ("/dev/urandom", 1024); + set_loglevel (llevel != L_NONE ? llevel : conf.llevel); - //OpenSSL_add_all_algorithms (); + RAND_load_file ("/dev/urandom", 1024); if (!THISNODE) { - slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), + slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting vped."), thisnode ? thisnode : ""); - exit (1); + exit (EXIT_FAILURE); } if (detach (do_detach)) - exit (0); + exit (EXIT_SUCCESS); setup_signals (); if (!network.setup ()) { - network.main_loop (); - cleanup_and_exit (1); + iom.loop (); + cleanup_and_exit (EXIT_FAILURE); } slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); - cleanup_and_exit (1); + cleanup_and_exit (EXIT_FAILURE); }