ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/gvpe.C
(Generate patch)

Comparing gvpe/src/gvpe.C (file contents):
Revision 1.1 by pcg, Fri Mar 18 01:53:05 2005 UTC vs.
Revision 1.10 by pcg, Sat Nov 10 05:14:22 2007 UTC

1/* 1/*
2 vped.C -- the main file for gvpe 2 gvpe.C -- the main file for gvpe
3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> 3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl>
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org> 4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
5 2003-2005 Marc Lehmann <gvpe@schmorp.de> 5 2003-2005 Marc Lehmann <gvpe@schmorp.de>
6 6
7 This file is part of GVPE. 7 This file is part of GVPE.
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with gvpe; if not, write to the Free Software 20 along with gvpe; if not, write to the Free Software
21 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22*/ 22*/
23 23
24#include "config.h" 24#include "config.h"
25 25
26#include <cstdio> 26#include <cstdio>
41#endif 41#endif
42 42
43#include <openssl/err.h> 43#include <openssl/err.h>
44#include <openssl/rand.h> 44#include <openssl/rand.h>
45 45
46#include "gettext.h"
46#include "pidfile.h" 47#include "pidfile.h"
47 48
48#include "conf.h" 49#include "conf.h"
49#include "slog.h" 50#include "slog.h"
50#include "util.h" 51#include "util.h"
51#include "vpn.h" 52#include "vpn.h"
52#include "iom.h" 53#include "ev_cpp.h"
53 54
54static loglevel llevel = L_NONE; 55static loglevel llevel = L_NONE;
55 56
56/* If nonzero, display usage information and exit. */ 57/* If nonzero, display usage information and exit. */
57static int show_help; 58static int show_help;
89 " -D, --no-detach Don't fork and detach.\n" 90 " -D, --no-detach Don't fork and detach.\n"
90 " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" 91 " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n"
91 " -L, --mlock Lock tinc into main memory.\n" 92 " -L, --mlock Lock tinc into main memory.\n"
92 " --help Display this help and exit.\n" 93 " --help Display this help and exit.\n"
93 " --version Output version information and exit.\n\n")); 94 " --version Output version information and exit.\n\n"));
94 printf (_("Report bugs to <vpe@plan9.de>.\n")); 95 printf (_("Report bugs to <gvpe@schmorp.de>.\n"));
95 } 96 }
96 97
97 exit (status); 98 exit (status);
98} 99}
99 100
101parse_options (int argc, char **argv, char **envp) 102parse_options (int argc, char **argv, char **envp)
102{ 103{
103 int r; 104 int r;
104 int option_index = 0; 105 int option_index = 0;
105 106
106 while ((r = getopt_long (argc, argv, "-c:DLl:", long_options, &option_index)) != EOF) 107 while ((r = getopt_long (argc, argv, "c:DLl:", long_options, &option_index)) != EOF)
107 { 108 {
108 switch (r) 109 switch (r)
109 { 110 {
110 case 0: /* long option */ 111 case 0: /* long option */
111 break;
112
113 case 1: /* this node name */
114 thisnode = strdup (optarg);
115 break; 112 break;
116 113
117 case 'c': /* config file */ 114 case 'c': /* config file */
118 confbase = strdup (optarg); 115 confbase = strdup (optarg);
119 break; 116 break;
164*/ 161*/
165RETSIGTYPE 162RETSIGTYPE
166sigterm_handler (int a) 163sigterm_handler (int a)
167{ 164{
168 network.events |= vpn::EVENT_SHUTDOWN; 165 network.events |= vpn::EVENT_SHUTDOWN;
169 network.event.start (0); 166 network.event.start ();
170} 167}
171 168
172RETSIGTYPE 169RETSIGTYPE
173sighup_handler (int a) 170sighup_handler (int a)
174{ 171{
175 network.events |= vpn::EVENT_RECONNECT; 172 network.events |= vpn::EVENT_RECONNECT;
176 network.event.start (0); 173 network.event.start ();
177} 174}
178 175
179RETSIGTYPE 176RETSIGTYPE
180sigusr1_handler (int a) 177sigusr1_handler (int a)
181{ 178{
218 bindtextdomain (PACKAGE, LOCALEDIR); 215 bindtextdomain (PACKAGE, LOCALEDIR);
219 textdomain (PACKAGE); 216 textdomain (PACKAGE);
220 217
221 parse_options (argc, argv, envp); 218 parse_options (argc, argv, envp);
222 219
220 argc -= optind;
221 argv += optind;
222
223 if (show_version) 223 if (show_version)
224 { 224 {
225 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), 225 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (),
226 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 226 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
227 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); 227 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
228 printf (_ 228 printf (_
229 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 229 ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n"
230 "See the AUTHORS file for a complete list.\n\n" 230 "See the AUTHORS file for a complete list.\n\n"
231 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 231 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
232 "and you are welcome to redistribute it under certain conditions;\n" 232 "and you are welcome to redistribute it under certain conditions;\n"
233 "see the file COPYING for details.\n")); 233 "see the file COPYING for details.\n"));
234 234
246 if (do_mlock) 246 if (do_mlock)
247 if (mlockall (MCL_CURRENT | MCL_FUTURE)) 247 if (mlockall (MCL_CURRENT | MCL_FUTURE))
248 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); 248 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno));
249#endif 249#endif
250 250
251 conf.read_config (true); 251 if (argc >= 1)
252 {
253 thisnode = *argv++;
254 argc--;
255 }
256
257 if (!ev::ev_default_loop (0))
258 {
259 slog (L_ERR, _("unable to initialise the event loop (bad $LIBEV_METHODS?)"));
260 exit (EXIT_FAILURE);
261 }
262
263 {
264 configuration_parser (conf, true, argc, argv);
265 }
252 266
253 set_loglevel (llevel != L_NONE ? llevel : conf.llevel); 267 set_loglevel (llevel != L_NONE ? llevel : conf.llevel);
254 268
255 RAND_load_file ("/dev/urandom", 1024); 269 RAND_load_file ("/dev/urandom", 1024);
256 270
257 if (!THISNODE) 271 if (!THISNODE)
258 { 272 {
259 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting vped."), 273 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting gvpe."),
260 thisnode ? thisnode : "<unset>"); 274 thisnode ? thisnode : "<unset>");
261 exit (EXIT_FAILURE); 275 exit (EXIT_FAILURE);
262 } 276 }
263 277
264 if (detach (do_detach)) 278 if (detach (do_detach))
266 280
267 setup_signals (); 281 setup_signals ();
268 282
269 if (!network.setup ()) 283 if (!network.setup ())
270 { 284 {
271 io_manager::loop (); 285 ev::ev_loop (0);
272 cleanup_and_exit (EXIT_FAILURE); 286 cleanup_and_exit (EXIT_FAILURE);
273 } 287 }
274 288
275 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); 289 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting."));
276 cleanup_and_exit (EXIT_FAILURE); 290 cleanup_and_exit (EXIT_FAILURE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines