… | |
… | |
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> |
… | |
… | |
48 | |
48 | |
49 | #include "conf.h" |
49 | #include "conf.h" |
50 | #include "slog.h" |
50 | #include "slog.h" |
51 | #include "util.h" |
51 | #include "util.h" |
52 | #include "vpn.h" |
52 | #include "vpn.h" |
53 | #include "iom.h" |
53 | #include "ev_cpp.h" |
54 | |
54 | |
55 | static loglevel llevel = L_NONE; |
55 | static loglevel llevel = L_NONE; |
56 | |
56 | |
57 | /* If nonzero, display usage information and exit. */ |
57 | /* If nonzero, display usage information and exit. */ |
58 | static int show_help; |
58 | static int show_help; |
… | |
… | |
90 | " -D, --no-detach Don't fork and detach.\n" |
90 | " -D, --no-detach Don't fork and detach.\n" |
91 | " -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" |
92 | " -L, --mlock Lock tinc into main memory.\n" |
92 | " -L, --mlock Lock tinc into main memory.\n" |
93 | " --help Display this help and exit.\n" |
93 | " --help Display this help and exit.\n" |
94 | " --version Output version information and exit.\n\n")); |
94 | " --version Output version information and exit.\n\n")); |
95 | printf (_("Report bugs to <vpe@plan9.de>.\n")); |
95 | printf (_("Report bugs to <gvpe@schmorp.de>.\n")); |
96 | } |
96 | } |
97 | |
97 | |
98 | exit (status); |
98 | exit (status); |
99 | } |
99 | } |
100 | |
100 | |
… | |
… | |
161 | */ |
161 | */ |
162 | RETSIGTYPE |
162 | RETSIGTYPE |
163 | sigterm_handler (int a) |
163 | sigterm_handler (int a) |
164 | { |
164 | { |
165 | network.events |= vpn::EVENT_SHUTDOWN; |
165 | network.events |= vpn::EVENT_SHUTDOWN; |
166 | network.event.start (0); |
166 | network.event.start (); |
167 | } |
167 | } |
168 | |
168 | |
169 | RETSIGTYPE |
169 | RETSIGTYPE |
170 | sighup_handler (int a) |
170 | sighup_handler (int a) |
171 | { |
171 | { |
172 | network.events |= vpn::EVENT_RECONNECT; |
172 | network.events |= vpn::EVENT_RECONNECT; |
173 | network.event.start (0); |
173 | network.event.start (); |
174 | } |
174 | } |
175 | |
175 | |
176 | RETSIGTYPE |
176 | RETSIGTYPE |
177 | sigusr1_handler (int a) |
177 | sigusr1_handler (int a) |
178 | { |
178 | { |
… | |
… | |
193 | act.sa_flags = 0; |
193 | act.sa_flags = 0; |
194 | |
194 | |
195 | act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); |
195 | act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); |
196 | act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); |
196 | act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); |
197 | act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); |
197 | act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); |
198 | // act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); |
198 | act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL); |
199 | act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL); |
199 | act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL); |
200 | act.sa_flags = SA_RESETHAND; |
200 | act.sa_flags = SA_RESETHAND; |
201 | act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); |
201 | act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); |
202 | act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); |
202 | act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); |
203 | } |
203 | } |
… | |
… | |
220 | argc -= optind; |
220 | argc -= optind; |
221 | argv += optind; |
221 | argv += optind; |
222 | |
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 | |
… | |
… | |
252 | { |
252 | { |
253 | thisnode = *argv++; |
253 | thisnode = *argv++; |
254 | argc--; |
254 | argc--; |
255 | } |
255 | } |
256 | |
256 | |
|
|
257 | if (!ev_default_loop (0)) |
|
|
258 | { |
|
|
259 | slog (L_ERR, _("unable to initialise the event loop (bad $LIBEV_METHODS?)")); |
|
|
260 | exit (EXIT_FAILURE); |
|
|
261 | } |
|
|
262 | |
257 | { |
263 | { |
258 | configuration_parser (conf, true, argc, argv); |
264 | configuration_parser (conf, true, argc, argv); |
259 | } |
265 | } |
260 | |
266 | |
261 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
267 | set_loglevel (llevel != L_NONE ? llevel : conf.llevel); |
… | |
… | |
274 | |
280 | |
275 | setup_signals (); |
281 | setup_signals (); |
276 | |
282 | |
277 | if (!network.setup ()) |
283 | if (!network.setup ()) |
278 | { |
284 | { |
279 | io_manager::loop (); |
285 | ev_loop (EV_DEFAULT_ 0); |
280 | cleanup_and_exit (EXIT_FAILURE); |
286 | cleanup_and_exit (EXIT_FAILURE); |
281 | } |
287 | } |
282 | |
288 | |
283 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
289 | slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); |
284 | cleanup_and_exit (EXIT_FAILURE); |
290 | cleanup_and_exit (EXIT_FAILURE); |