… | |
… | |
41 | #include "pidfile.h" |
41 | #include "pidfile.h" |
42 | |
42 | |
43 | #include "conf.h" |
43 | #include "conf.h" |
44 | #include "slog.h" |
44 | #include "slog.h" |
45 | #include "util.h" |
45 | #include "util.h" |
46 | #include "protocol.h" |
46 | #include "vpn.h" |
|
|
47 | #include "iom.h" |
47 | |
48 | |
48 | vpn network; |
49 | vpn network; |
49 | |
50 | |
50 | static loglevel llevel = L_NONE; |
51 | static loglevel llevel = L_NONE; |
51 | |
52 | |
… | |
… | |
166 | */ |
167 | */ |
167 | RETSIGTYPE |
168 | RETSIGTYPE |
168 | sigterm_handler (int a) |
169 | sigterm_handler (int a) |
169 | { |
170 | { |
170 | network.events |= vpn::EVENT_SHUTDOWN; |
171 | network.events |= vpn::EVENT_SHUTDOWN; |
|
|
172 | network.event.start (0); |
171 | } |
173 | } |
172 | |
174 | |
173 | RETSIGTYPE |
175 | RETSIGTYPE |
174 | sighup_handler (int a) |
176 | sighup_handler (int a) |
175 | { |
177 | { |
176 | network.events |= vpn::EVENT_RECONNECT; |
178 | network.events |= vpn::EVENT_RECONNECT; |
|
|
179 | network.event.start (0); |
177 | } |
180 | } |
178 | |
181 | |
179 | RETSIGTYPE |
182 | RETSIGTYPE |
180 | sigusr1_handler (int a) |
183 | sigusr1_handler (int a) |
181 | { |
184 | { |
|
|
185 | network.dump_status (); |
182 | } |
186 | } |
183 | |
187 | |
184 | RETSIGTYPE |
188 | RETSIGTYPE |
185 | sigusr2_handler (int a) |
189 | sigusr2_handler (int a) |
186 | { |
190 | { |
… | |
… | |
196 | |
200 | |
197 | act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); |
201 | act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); |
198 | act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); |
202 | act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); |
199 | act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); |
203 | act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); |
200 | act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); |
204 | act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); |
|
|
205 | act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL); |
201 | act.sa_flags = SA_RESETHAND; |
206 | act.sa_flags = SA_RESETHAND; |
202 | act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); |
207 | act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); |
203 | act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); |
208 | act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); |
204 | } |
209 | } |
205 | |
210 | |
… | |
… | |
248 | |
253 | |
249 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
254 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
250 | |
255 | |
251 | RAND_load_file ("/dev/urandom", 1024); |
256 | RAND_load_file ("/dev/urandom", 1024); |
252 | |
257 | |
253 | if (!thisnode) |
258 | if (!THISNODE) |
254 | { |
259 | { |
255 | slog (L_ERR, _("current node not set, or node '%s' not found in configfile, use the -n switch when starting vped."), |
260 | 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>"); |
261 | thisnode ? thisnode : "<unset>"); |
257 | exit (1); |
262 | exit (1); |
258 | } |
263 | } |
… | |
… | |
262 | |
267 | |
263 | setup_signals (); |
268 | setup_signals (); |
264 | |
269 | |
265 | if (!network.setup ()) |
270 | if (!network.setup ()) |
266 | { |
271 | { |
267 | network.main_loop (); |
272 | iom.loop (); |
268 | cleanup_and_exit (1); |
273 | cleanup_and_exit (1); |
269 | } |
274 | } |
270 | |
275 | |
271 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
276 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
272 | cleanup_and_exit (1); |
277 | cleanup_and_exit (1); |