|
@@ -14,7 +14,6 @@
|
|
|
|
|
|
|
|
|
static void dumpstats(int severity);
|
|
|
-static int init_from_config(int argc, char **argv);
|
|
|
|
|
|
|
|
|
|
|
@@ -689,72 +688,6 @@ static int prepare_for_poll(void) {
|
|
|
return (1000 - (now.tv_usec / 1000));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * configuration file.
|
|
|
- */
|
|
|
-static int init_from_config(int argc, char **argv) {
|
|
|
- or_options_t *options;
|
|
|
-
|
|
|
-
|
|
|
- if(getconfig(argc,argv) < 0) {
|
|
|
- log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- options = get_options();
|
|
|
-
|
|
|
-
|
|
|
- if(options->User || options->Group) {
|
|
|
- if(switch_id(options->User, options->Group) != 0) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (get_data_directory() &&
|
|
|
- check_private_dir(get_data_directory(), 1) != 0) {
|
|
|
- log_fn(LOG_ERR, "Couldn't access/create private data directory %s",
|
|
|
- get_data_directory());
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * to not fork, and to log stuff to stderr. */
|
|
|
- if (options->command != CMD_RUN_TOR)
|
|
|
- return 0;
|
|
|
-
|
|
|
-
|
|
|
- if (config_init_logs(options)<0)
|
|
|
- return -1;
|
|
|
-
|
|
|
- * gone. */
|
|
|
- close_temp_logs();
|
|
|
- add_callback_log(LOG_WARN, LOG_ERR, control_event_logmsg);
|
|
|
-
|
|
|
-
|
|
|
- if (options->RunAsDaemon) {
|
|
|
- start_daemon(get_data_directory());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- connection_bucket_init();
|
|
|
- stats_prev_global_read_bucket = global_read_bucket;
|
|
|
- stats_prev_global_write_bucket = global_write_bucket;
|
|
|
-
|
|
|
-
|
|
|
- if(options->RunAsDaemon) {
|
|
|
-
|
|
|
- finish_daemon();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * will log a warning */
|
|
|
- if(options->PidFile)
|
|
|
- write_pidfile(options->PidFile);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
* retry all connections, re-upload all descriptors, and so on. */
|
|
|
static int do_hup(void) {
|
|
@@ -766,17 +699,11 @@ static int do_hup(void) {
|
|
|
|
|
|
|
|
|
if (init_from_config(0, NULL) < 0) {
|
|
|
+ log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
|
|
return -1;
|
|
|
}
|
|
|
-
|
|
|
- if (rend_service_load_keys()<0) {
|
|
|
- log_fn(LOG_ERR,"Error reloading rendezvous service keys");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if(retry_all_listeners(1) < 0) {
|
|
|
- log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
|
|
|
- return -1;
|
|
|
- }
|
|
|
+
|
|
|
+ * removed from init_keys() */
|
|
|
if(authdir_mode(get_options())) {
|
|
|
|
|
|
tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", get_data_directory());
|
|
@@ -816,11 +743,17 @@ static int do_main_loop(void) {
|
|
|
|
|
|
|
|
|
* TLS context. */
|
|
|
- if (init_keys() < 0 || rend_service_load_keys() < 0) {
|
|
|
+ if (init_keys() < 0) {
|
|
|
log_fn(LOG_ERR,"Error initializing keys; exiting");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ connection_bucket_init();
|
|
|
+ stats_prev_global_read_bucket = global_read_bucket;
|
|
|
+ stats_prev_global_write_bucket = global_write_bucket;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if (get_options()->AccountingMaxKB)
|
|
|
configure_accounting(time(NULL));
|
|
@@ -840,12 +773,6 @@ static int do_main_loop(void) {
|
|
|
cpu_init();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if(retry_all_listeners(1) < 0) {
|
|
|
- log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
for(;;) {
|
|
|
#ifdef MS_WINDOWS_SERVICE
|
|
|
if (service_status.dwCurrentState != SERVICE_RUNNING) {
|
|
@@ -1079,8 +1006,10 @@ static int tor_init(int argc, char *argv[]) {
|
|
|
}
|
|
|
atexit(exit_function);
|
|
|
|
|
|
- if (init_from_config(argc,argv) < 0)
|
|
|
+ if (init_from_config(argc,argv) < 0) {
|
|
|
+ log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
|
|
|
return -1;
|
|
|
+ }
|
|
|
|
|
|
#ifndef MS_WINDOWS
|
|
|
if(geteuid()==0)
|
|
@@ -1090,15 +1019,10 @@ static int tor_init(int argc, char *argv[]) {
|
|
|
if(server_mode(get_options())) {
|
|
|
dns_init();
|
|
|
}
|
|
|
- if(proxy_mode(get_options())) {
|
|
|
- client_dns_init();
|
|
|
- }
|
|
|
+ client_dns_init();
|
|
|
|
|
|
handle_signals(1);
|
|
|
|
|
|
- if (set_max_file_descriptors(get_options()->MaxConn) < 0)
|
|
|
- return -1;
|
|
|
-
|
|
|
crypto_global_init();
|
|
|
crypto_seed_rng();
|
|
|
return 0;
|