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

Comparing gvpe/src/vped.C (file contents):
Revision 1.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.8 by pcg, Mon Sep 1 21:23:35 2003 UTC

33#include <signal.h> 33#include <signal.h>
34#include <termios.h> 34#include <termios.h>
35 35
36#include <sys/mman.h> 36#include <sys/mman.h>
37 37
38#include <openssl/err.h>
38#include <openssl/rand.h> 39#include <openssl/rand.h>
39 40
40#include "gettext.h" 41#include "gettext.h"
41#include "pidfile.h" 42#include "pidfile.h"
42 43
43#include "conf.h" 44#include "conf.h"
44#include "slog.h" 45#include "slog.h"
45#include "util.h" 46#include "util.h"
46#include "protocol.h" 47#include "vpn.h"
48#include "iom.h"
47 49
48vpn network; 50vpn network;
51
52static loglevel llevel = L_NONE;
49 53
50/* If nonzero, display usage information and exit. */ 54/* If nonzero, display usage information and exit. */
51static int show_help; 55static int show_help;
52 56
53/* If nonzero, print the version on standard output and exit. */ 57/* If nonzero, print the version on standard output and exit. */
126 break; 130 break;
127#endif 131#endif
128 132
129 case 'l': /* inc debug level */ 133 case 'l': /* inc debug level */
130 { 134 {
131 loglevel l = string_to_loglevel (optarg); 135 llevel = string_to_loglevel (optarg);
132 136
133 if (l != L_NONE) 137 if (llevel == L_NONE)
134 set_loglevel (l);
135 else
136 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); 138 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL);
137 } 139 }
138 break; 140 break;
139 141
140 case '?': 142 case '?':
166*/ 168*/
167RETSIGTYPE 169RETSIGTYPE
168sigterm_handler (int a) 170sigterm_handler (int a)
169{ 171{
170 network.events |= vpn::EVENT_SHUTDOWN; 172 network.events |= vpn::EVENT_SHUTDOWN;
173 network.event.start (0);
171} 174}
172 175
173RETSIGTYPE 176RETSIGTYPE
174sighup_handler (int a) 177sighup_handler (int a)
175{ 178{
176 network.events |= vpn::EVENT_RECONNECT; 179 network.events |= vpn::EVENT_RECONNECT;
180 network.event.start (0);
177} 181}
178 182
179RETSIGTYPE 183RETSIGTYPE
180sigusr1_handler (int a) 184sigusr1_handler (int a)
181{ 185{
186 network.dump_status ();
182} 187}
183 188
184RETSIGTYPE 189RETSIGTYPE
185sigusr2_handler (int a) 190sigusr2_handler (int a)
186{ 191{
196 201
197 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); 202 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL);
198 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); 203 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL);
199 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); 204 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL);
200 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); 205 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL);
206 act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL);
201 act.sa_flags = SA_RESETHAND; 207 act.sa_flags = SA_RESETHAND;
202 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); 208 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL);
203 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); 209 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL);
204} 210}
205 211
206int 212int
207main (int argc, char **argv, char **envp) 213main (int argc, char **argv, char **envp)
208{ 214{
215 ERR_load_crypto_strings (); // we have the RAM
216
209 set_loglevel (L_INFO); 217 set_loglevel (L_INFO);
210 set_identity (argv[0]); 218 set_identity (argv[0]);
211 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 219 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
212 220
213 setlocale (LC_ALL, ""); 221 setlocale (LC_ALL, "");
216 224
217 parse_options (argc, argv, envp); 225 parse_options (argc, argv, envp);
218 226
219 if (show_version) 227 if (show_version)
220 { 228 {
221 printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), 229 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (),
222 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 230 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
223 printf (_ 231 printf (_
224 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 232 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n"
225 "See the AUTHORS file for a complete list.\n\n" 233 "See the AUTHORS file for a complete list.\n\n"
226 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 234 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
244#endif 252#endif
245 253
246 make_names (); 254 make_names ();
247 conf.read_config (true); 255 conf.read_config (true);
248 256
257 set_loglevel (llevel != L_NONE ? llevel : conf.llevel);
258
249 RAND_load_file ("/dev/urandom", 1024); 259 RAND_load_file ("/dev/urandom", 1024);
250
251 //OpenSSL_add_all_algorithms ();
252 260
253 if (!THISNODE) 261 if (!THISNODE)
254 { 262 {
255 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), 263 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."),
256 thisnode ? thisnode : "<unset>"); 264 thisnode ? thisnode : "<unset>");
262 270
263 setup_signals (); 271 setup_signals ();
264 272
265 if (!network.setup ()) 273 if (!network.setup ())
266 { 274 {
267 network.main_loop (); 275 iom.loop ();
268 cleanup_and_exit (1); 276 cleanup_and_exit (1);
269 } 277 }
270 278
271 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); 279 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting."));
272 cleanup_and_exit (1); 280 cleanup_and_exit (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines