bool use_logfile = false;
char *identname = NULL; /* program name for syslog */
-char *controlsocketname = NULL; /* control socket location */
char *logfilename = NULL; /* log file location */
+char *controlcookiename = NULL;
char **g_argv; /* a copy of the cmdline arguments */
static int status;
{"chroot", no_argument, NULL, 'R'},
{"user", required_argument, NULL, 'U'},
{"logfile", optional_argument, NULL, 4},
- {"controlsocket", required_argument, NULL, 5},
+ {"controlcookie", required_argument, NULL, 5},
{NULL, 0, NULL, 0}
};
" -n, --net=NETNAME Connect to net NETNAME.\n"
" -L, --mlock Lock tinc into main memory.\n"
" --logfile[=FILENAME] Write log entries to a logfile.\n"
- " --controlsocket=FILENAME Open control socket at FILENAME.\n"
+ " --controlcookie=FILENAME Write control socket cookie to FILENAME.\n"
" --bypass-security Disables meta protocol security, for debugging.\n"
" -R, --chroot chroot to NET dir at startup.\n"
" -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n"
break;
case 5: /* open control socket here */
- controlsocketname = xstrdup(optarg);
+ controlcookiename = xstrdup(optarg);
break;
case '?':
else
xasprintf(&confbase, "%s", installdir);
}
+ if(!controlcookiename)
+ xasprintf(&controlcookiename, "%s/cookie", confbase);
}
RegCloseKey(key);
if(*installdir)
}
#endif
- if(!controlsocketname)
- xasprintf(&controlsocketname, "%s/run/%s.control/socket", LOCALSTATEDIR, identname);
-
if(!logfilename)
xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
+ if(!controlcookiename)
+ xasprintf(&controlcookiename, LOCALSTATEDIR "/run/%s.cookie", identname);
+
if(netname) {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
static void free_names() {
if (identname) free(identname);
if (netname) free(netname);
- if (controlsocketname) free(controlsocketname);
+ if (controlcookiename) free(controlcookiename);
if (logfilename) free(logfilename);
if (confbase) free(confbase);
}
return 0;
}
+#ifdef HAVE_MINGW
+ if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
+ logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
+ return 1;
+ }
+#endif
+
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
if(!event_init()) {
return 1;
}
- if(!init_control())
- return 1;
-
g_argv = argv;
init_configuration(&config_tree);
}
#ifdef HAVE_MINGW
- if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
- logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
- return 1;
- }
-
if(!do_detach || !init_service())
return main2(argc, argv);
else
if(!setup_network())
goto end;
+ if(!init_control())
+ return 1;
+
/* Initiate all outgoing connections. */
try_outgoing_connections();
end:
logger(LOG_NOTICE, "Terminating");
-#ifndef HAVE_MINGW
exit_control();
-#endif
crypto_exit();