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.12 by pcg, Sat Dec 1 23:35:31 2007 UTC vs.
Revision 1.21 by root, Wed Oct 12 22:51:10 2011 UTC

1/* 1/*
2 gvpe.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-2011 Marc Lehmann <gvpe@schmorp.de>
6 6
7 This file is part of GVPE. 7 This file is part of GVPE.
8 8
9 GVPE is free software; you can redistribute it and/or modify 9 GVPE is free software; you can redistribute it and/or modify it
10 it under the terms of the GNU General Public License as published by 10 under the terms of the GNU General Public License as published by the
11 the Free Software Foundation; either version 2 of the License, or 11 Free Software Foundation; either version 3 of the License, or (at your
12 (at your option) any later version. 12 option) any later version.
13 13
14 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful, but
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 GNU General Public License for more details. 17 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 along
20 along with gvpe; if not, write to the Free Software 20 with this program; if not, see <http://www.gnu.org/licenses/>.
21 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21
22 Additional permission under GNU GPL version 3 section 7
23
24 If you modify this Program, or any covered work, by linking or
25 combining it with the OpenSSL project's OpenSSL library (or a modified
26 version of that library), containing parts covered by the terms of the
27 OpenSSL or SSLeay licenses, the licensors of this Program grant you
28 additional permission to convey the resulting work. Corresponding
29 Source for a non-source form of such a combination shall include the
30 source code for the parts of OpenSSL used as well as that of the
31 covered work.
22*/ 32*/
23 33
24#include "config.h" 34#include "config.h"
25 35
26#include <cstdio> 36#include <cstdio>
65 75
66/* If zero, don't detach from the terminal. */ 76/* If zero, don't detach from the terminal. */
67static int do_detach = 1; 77static int do_detach = 1;
68 78
69static struct option const long_options[] = 79static struct option const long_options[] =
70 { 80{
71 {"config", required_argument, NULL, 'c'}, 81 {"config", required_argument, NULL, 'c'},
72 {"help", no_argument, &show_help, 1}, 82 {"help", no_argument, &show_help, 1},
73 {"version", no_argument, &show_version, 1}, 83 {"version", no_argument, &show_version, 1},
74 {"no-detach", no_argument, &do_detach, 0}, 84 {"no-detach", no_argument, &do_detach, 0},
75 {"log-level", required_argument, NULL, 'l'}, 85 {"log-level", required_argument, NULL, 'l'},
76 {"mlock", no_argument, &do_mlock, 1}, 86 {"mlock", no_argument, &do_mlock, 1},
77 {NULL, 0, NULL, 0} 87 {NULL, 0, NULL, 0}
78 }; 88};
79 89
80static void 90static void
81usage (int status) 91usage (int status)
82{ 92{
83 if (status != 0) 93 if (status != 0)
87 printf (_("Usage: %s [option]... NODENAME\n\n"), get_identity ()); 97 printf (_("Usage: %s [option]... NODENAME\n\n"), get_identity ());
88 printf (_ 98 printf (_
89 (" -c, --config=DIR Read configuration options from DIR.\n" 99 (" -c, --config=DIR Read configuration options from DIR.\n"
90 " -D, --no-detach Don't fork and detach.\n" 100 " -D, --no-detach Don't fork and detach.\n"
91 " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n" 101 " -l, --log-level=LEVEL Set logging level (info, notice, warn are common).\n"
92 " -L, --mlock Lock tinc into main memory.\n" 102 " -L, --mlock Lock gvpe into main memory.\n"
93 " --help Display this help and exit.\n" 103 " --help Display this help and exit.\n"
94 " --version Output version information and exit.\n\n")); 104 " --version Output version information and exit.\n\n"));
95 printf (_("Report bugs to <gvpe@schmorp.de>.\n")); 105 printf (_("Report bugs to <gvpe@schmorp.de>.\n"));
96 } 106 }
97 107
98 exit (status); 108 exit (status);
99} 109}
100 110
101void 111static void
102parse_options (int argc, char **argv, char **envp) 112parse_options (int argc, char **argv, char **envp)
103{ 113{
104 int r; 114 int r;
105 int option_index = 0; 115 int option_index = 0;
106 116
139 break; 149 break;
140 } 150 }
141 } 151 }
142} 152}
143 153
144/*
145 Close network connections, and terminate neatly 154// close network connections, and terminate neatly
146*/ 155static void
147void cleanup_and_exit(int c) 156cleanup_and_exit (int c)
148{ 157{
149 network.shutdown_all (); 158 network.shutdown_all ();
150 159
151 if (conf.pidfilename) 160 if (conf.pidfilename)
152 remove_pid (conf.pidfilename); 161 remove_pid (conf.pidfilename);
154 slog (L_INFO, _("terminating with exit code %d"), c); 163 slog (L_INFO, _("terminating with exit code %d"), c);
155 164
156 exit (c); 165 exit (c);
157} 166}
158 167
159/*
160 Signal handlers. 168// signal handlers
161*/ 169static RETSIGTYPE
162RETSIGTYPE
163sigterm_handler (int a) 170sigterm_handler (int a)
164{ 171{
165 network.events |= vpn::EVENT_SHUTDOWN; 172 network.events |= vpn::EVENT_SHUTDOWN;
166 network.event.start (); 173 network.event.start ();
167} 174}
168 175
169RETSIGTYPE 176static RETSIGTYPE
170sighup_handler (int a) 177sighup_handler (int a)
171{ 178{
172 network.events |= vpn::EVENT_RECONNECT; 179 network.events |= vpn::EVENT_RECONNECT;
173 network.event.start (); 180 network.event.start ();
174} 181}
175 182
176RETSIGTYPE 183static RETSIGTYPE
177sigusr1_handler (int a) 184sigusr1_handler (int a)
178{ 185{
179 network.dump_status (); 186 network.dump_status ();
180} 187}
181 188
182RETSIGTYPE 189static RETSIGTYPE
183sigusr2_handler (int a) 190sigusr2_handler (int a)
184{ 191{
185} 192}
186 193
187void 194static void
188setup_signals (void) 195setup_signals (void)
189{ 196{
190 struct sigaction act; 197 struct sigaction act;
191 198
192 sigfillset (&act.sa_mask); 199 sigfillset (&act.sa_mask);
193 act.sa_flags = 0; 200 act.sa_flags = 0;
194 201
195 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL); 202 act.sa_handler = sighup_handler; sigaction (SIGHUP , &act, NULL);
196 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL); 203 act.sa_handler = sigusr1_handler; sigaction (SIGUSR1, &act, NULL);
197 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL); 204 act.sa_handler = sigusr2_handler; sigaction (SIGUSR2, &act, NULL);
198 act.sa_handler = SIG_IGN; sigaction (SIGCHLD, &act, NULL);
199 act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL); 205 act.sa_handler = SIG_IGN; sigaction (SIGPIPE, &act, NULL);
200 act.sa_flags = SA_RESETHAND; 206 act.sa_flags = SA_RESETHAND;
201 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); 207 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL);
202 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); 208 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL);
203} 209}
224 { 230 {
225 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (), 231 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (),
226 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 232 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
227 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); 233 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
228 printf (_ 234 printf (_
229 ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n" 235 ("Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> and others.\n"
230 "See the AUTHORS file for a complete list.\n\n" 236 "See the AUTHORS file for a complete list.\n\n"
231 "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 237 "GVPE comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
232 "and you are welcome to redistribute it under certain conditions;\n" 238 "and you are welcome to redistribute it under certain conditions;\n"
233 "see the file COPYING for details.\n")); 239 "see the file COPYING for details.\n"));
234 240
235 return 0; 241 return 0;
236 } 242 }
280 286
281 setup_signals (); 287 setup_signals ();
282 288
283 if (!network.setup ()) 289 if (!network.setup ())
284 { 290 {
285 ev_loop (EV_DEFAULT_ 0); 291 ev_run (EV_DEFAULT_ 0);
286 cleanup_and_exit (EXIT_FAILURE); 292 cleanup_and_exit (EXIT_FAILURE);
287 } 293 }
288 294
289 slog (L_ERR, _("unable to setup network, unrecoverable error, exiting.")); 295 slog (L_ERR, _("unrecoverable error while setting up network, exiting."));
290 cleanup_and_exit (EXIT_FAILURE); 296 cleanup_and_exit (EXIT_FAILURE);
291} 297}
292 298

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines