X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ftincd.c;h=989eb76d130ef20ab99c45eb0d75ff7e1d323653;hp=6bd92ecb3f67e4bf9741a840a7b153eed6b098c0;hb=81f5713ab71944d51703653eab7f364fba0c482e;hpb=f75dcef72a81a337e847adf0bae54198894f65b9 diff --git a/src/tincd.c b/src/tincd.c index 6bd92ecb..989eb76d 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10.4.63 2002/09/09 21:25:16 guus Exp $ + $Id: tincd.c,v 1.10.4.69 2003/07/06 17:15:25 guus Exp $ */ #include "config.h" @@ -33,6 +33,12 @@ #include #include #include + +/* Darwin (MacOS/X) needs the following definition... */ +#ifndef _P1003_1B_VISIBLE +#define _P1003_1B_VISIBLE +#endif + #include #ifdef HAVE_SYS_IOCTL_H @@ -44,6 +50,8 @@ #include #include +#include + #include #include @@ -57,13 +65,13 @@ #include "system.h" /* The name this program was run with. */ -char *program_name; +char *program_name = NULL; /* If nonzero, display usage information and exit. */ -int show_help; +int show_help = 0; /* If nonzero, print the version on standard output and exit. */ -int show_version; +int show_version = 0; /* If nonzero, it will attempt to kill a running tincd and exit. */ int kill_tincd = 0; @@ -77,8 +85,8 @@ int bypass_security = 0; /* If nonzero, disable swapping for this process. */ int do_mlock = 0; -char *identname; /* program name for syslog */ -char *pidfilename; /* pid file location */ +char *identname = NULL; /* program name for syslog */ +char *pidfilename = NULL; /* pid file location */ char **g_argv; /* a copy of the cmdline arguments */ char **environment; /* A pointer to the environment on startup */ @@ -104,8 +112,7 @@ static void usage(int status) program_name); else { printf(_("Usage: %s [option]...\n\n"), program_name); - printf(_ - (" -c, --config=DIR Read configuration options from DIR.\n" + printf(_(" -c, --config=DIR Read configuration options from DIR.\n" " -D, --no-detach Don't fork and detach.\n" " -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n" " -k, --kill[=SIGNAL] Attempt to kill a running tincd and exit.\n" @@ -172,9 +179,7 @@ void parse_options(int argc, char **argv, char **envp) kill_tincd = atoi(optarg); if(!kill_tincd) { - fprintf(stderr, - _ - ("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"), + fprintf(stderr, _("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"), optarg); usage(1); } @@ -193,9 +198,7 @@ void parse_options(int argc, char **argv, char **envp) generate_keys = atoi(optarg); if(generate_keys < 512) { - fprintf(stderr, - _ - ("Invalid argument `%s'; BITS must be a number equal to or greater than 512.\n"), + fprintf(stderr, _("Invalid argument `%s'; BITS must be a number equal to or greater than 512.\n"), optarg); usage(1); } @@ -344,6 +347,7 @@ int main(int argc, char **argv, char **envp) environment = envp; parse_options(argc, argv, envp); + make_names(); if(show_version) { printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE, @@ -360,6 +364,9 @@ int main(int argc, char **argv, char **envp) if(show_help) usage(0); + if(kill_tincd) + exit(kill_other(kill_tincd)); + #ifndef LOG_PERROR openlog("tinc", LOG_CONS, LOG_DAEMON); /* Catch all syslog() calls issued before detaching */ #else @@ -382,33 +389,30 @@ int main(int argc, char **argv, char **envp) g_argv = argv; - make_names(); init_configuration(&config_tree); /* Slllluuuuuuurrrrp! */ RAND_load_file("/dev/urandom", 1024); -#ifdef HAVE_SSLEAY_ADD_ALL_ALGORITHMS - SSLeay_add_all_algorithms(); -#else OpenSSL_add_all_algorithms(); -#endif if(generate_keys) { read_server_config(); exit(keygen(generate_keys)); } - if(kill_tincd) - exit(kill_other(kill_tincd)); - if(read_server_config()) exit(1); + if(lzo_init() != LZO_E_OK) { + syslog(LOG_ERR, _("Error initializing LZO compressor!")); + exit(1); + } + if(detach()) exit(0); - + for(;;) { if(!setup_network_connections()) { main_loop();