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.10 by pcg, Tue Oct 14 19:57:55 2003 UTC

31#include <sys/types.h> 31#include <sys/types.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <signal.h> 33#include <signal.h>
34#include <termios.h> 34#include <termios.h>
35 35
36#if HAVE_SYS_MMAN_H
36#include <sys/mman.h> 37# include <sys/mman.h>
38#endif
37 39
40#include <openssl/err.h>
38#include <openssl/rand.h> 41#include <openssl/rand.h>
39 42
40#include "gettext.h" 43#include "gettext.h"
41#include "pidfile.h" 44#include "pidfile.h"
42 45
43#include "conf.h" 46#include "conf.h"
44#include "slog.h" 47#include "slog.h"
45#include "util.h" 48#include "util.h"
46#include "protocol.h" 49#include "vpn.h"
50#include "iom.h"
47 51
48vpn network; 52vpn network;
53
54static loglevel llevel = L_NONE;
49 55
50/* If nonzero, display usage information and exit. */ 56/* If nonzero, display usage information and exit. */
51static int show_help; 57static int show_help;
52 58
53/* If nonzero, print the version on standard output and exit. */ 59/* If nonzero, print the version on standard output and exit. */
54static int show_version; 60static int show_version;
55 61
56#if HAVE_MLOCKALL
57/* If nonzero, disable swapping for this process. */ 62/* If nonzero, disable swapping for this process. */
58static int do_mlock = 0; 63static int do_mlock = 0;
59#endif
60 64
61/* If zero, don't detach from the terminal. */ 65/* If zero, don't detach from the terminal. */
62static int do_detach = 1; 66static int do_detach = 1;
63 67
64static struct option const long_options[] = 68static struct option const long_options[] =
66 {"config", required_argument, NULL, 'c'}, 70 {"config", required_argument, NULL, 'c'},
67 {"help", no_argument, &show_help, 1}, 71 {"help", no_argument, &show_help, 1},
68 {"version", no_argument, &show_version, 1}, 72 {"version", no_argument, &show_version, 1},
69 {"no-detach", no_argument, &do_detach, 0}, 73 {"no-detach", no_argument, &do_detach, 0},
70 {"log-level", required_argument, NULL, 'l'}, 74 {"log-level", required_argument, NULL, 'l'},
71#if HAVE_MLOCKALL
72 {"mlock", no_argument, &do_mlock, 1}, 75 {"mlock", no_argument, &do_mlock, 1},
73#endif
74 {NULL, 0, NULL, 0} 76 {NULL, 0, NULL, 0}
75 }; 77 };
76 78
77static void 79static void
78usage (int status) 80usage (int status)
118 120
119 case 'D': /* no detach */ 121 case 'D': /* no detach */
120 do_detach = 0; 122 do_detach = 0;
121 break; 123 break;
122 124
123#if HAVE_MLOCKALL
124 case 'L': /* lock into memory */ 125 case 'L': /* lock into memory */
125 do_mlock = 1; 126 do_mlock = 1;
126 break; 127 break;
127#endif
128 128
129 case 'l': /* inc debug level */ 129 case 'l': /* inc debug level */
130 { 130 {
131 loglevel l = string_to_loglevel (optarg); 131 llevel = string_to_loglevel (optarg);
132 132
133 if (l != L_NONE) 133 if (llevel == L_NONE)
134 set_loglevel (l);
135 else
136 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL); 134 slog (L_WARN, "'%s': %s", optarg, UNKNOWN_LOGLEVEL);
137 } 135 }
138 break; 136 break;
139 137
140 case '?': 138 case '?':
166*/ 164*/
167RETSIGTYPE 165RETSIGTYPE
168sigterm_handler (int a) 166sigterm_handler (int a)
169{ 167{
170 network.events |= vpn::EVENT_SHUTDOWN; 168 network.events |= vpn::EVENT_SHUTDOWN;
169 network.event.start (0);
171} 170}
172 171
173RETSIGTYPE 172RETSIGTYPE
174sighup_handler (int a) 173sighup_handler (int a)
175{ 174{
176 network.events |= vpn::EVENT_RECONNECT; 175 network.events |= vpn::EVENT_RECONNECT;
176 network.event.start (0);
177} 177}
178 178
179RETSIGTYPE 179RETSIGTYPE
180sigusr1_handler (int a) 180sigusr1_handler (int a)
181{ 181{
182 network.dump_status ();
182} 183}
183 184
184RETSIGTYPE 185RETSIGTYPE
185sigusr2_handler (int a) 186sigusr2_handler (int a)
186{ 187{
196 197
197 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); 198 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL);
198 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); 199 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL);
199 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); 200 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL);
200 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); 201 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL);
202 act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL);
201 act.sa_flags = SA_RESETHAND; 203 act.sa_flags = SA_RESETHAND;
202 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); 204 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL);
203 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); 205 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL);
204} 206}
205 207
206int 208int
207main (int argc, char **argv, char **envp) 209main (int argc, char **argv, char **envp)
208{ 210{
211 ERR_load_crypto_strings (); // we have the RAM
212
209 set_loglevel (L_INFO); 213 set_loglevel (L_INFO);
210 set_identity (argv[0]); 214 set_identity (argv[0]);
211 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 215 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
212 216
213 setlocale (LC_ALL, ""); 217 setlocale (LC_ALL, "");
216 220
217 parse_options (argc, argv, envp); 221 parse_options (argc, argv, envp);
218 222
219 if (show_version) 223 if (show_version)
220 { 224 {
221 printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), 225 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (),
222 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 226 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
223 printf (_ 227 printf (_
224 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 228 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n"
225 "See the AUTHORS file for a complete list.\n\n" 229 "See the AUTHORS file for a complete list.\n\n"
226 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 230 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
235 239
236 log_to (LOGTO_SYSLOG | LOGTO_STDERR); 240 log_to (LOGTO_SYSLOG | LOGTO_STDERR);
237 241
238 /* Lock all pages into memory if requested */ 242 /* Lock all pages into memory if requested */
239 243
240#if HAVE_MLOCKALL 244#if HAVE_MLOCKALL && HAVE_SYS_MMAN_H && _POSIX_MEMLOCK
241 if (do_mlock) 245 if (do_mlock)
242 if (mlockall (MCL_CURRENT | MCL_FUTURE)) 246 if (mlockall (MCL_CURRENT | MCL_FUTURE))
243 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno)); 247 slog (L_ERR, _("system call `%s' failed: %s"), "mlockall", strerror (errno));
244#endif 248#endif
245 249
246 make_names (); 250 make_names ();
247 conf.read_config (true); 251 conf.read_config (true);
248 252
253 set_loglevel (llevel != L_NONE ? llevel : conf.llevel);
254
249 RAND_load_file ("/dev/urandom", 1024); 255 RAND_load_file ("/dev/urandom", 1024);
250
251 //OpenSSL_add_all_algorithms ();
252 256
253 if (!THISNODE) 257 if (!THISNODE)
254 { 258 {
255 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), 259 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>"); 260 thisnode ? thisnode : "<unset>");
262 266
263 setup_signals (); 267 setup_signals ();
264 268
265 if (!network.setup ()) 269 if (!network.setup ())
266 { 270 {
267 network.main_loop (); 271 iom.loop ();
268 cleanup_and_exit (1); 272 cleanup_and_exit (1);
269 } 273 }
270 274
271 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); 275 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting."));
272 cleanup_and_exit (1); 276 cleanup_and_exit (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines