Commit 04d42ea4 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

rotate dns and cpu workers if the controller changes options that

will affect them.


svn:r4787
parent b1d3f124
......@@ -1978,6 +1978,26 @@ options_transition_allowed(or_options_t *old, or_options_t *new_val)
return 0;
}
/** Return 1 if any option in <b>lines</b> will require us to rotate
* the cpu and dns workers; else return 0. */
int
options_transition_affects_workers(config_line_t *lines)
{
config_line_t *p;
config_var_t *var;
for (p = lines; p; p = p->next) {
var = config_find_option(&options_format, p->key);
if (!var) continue;
if (!strcasecmp(var->name, "datadirectory") ||
!strcasecmp(var->name, "log") ||
!strcasecmp(var->name, "numcpus") ||
!strcasecmp(var->name, "orport") ||
!strcasecmp(var->name, "safelogging"))
return 1;
}
return 0;
}
#ifdef MS_WINDOWS
/** Return the directory on windows where we expect to find our application
* data. */
......
......@@ -681,11 +681,16 @@ handle_control_setconf(connection_t *conn, uint32_t len, char *body)
return 0;
}
config_free_lines(lines);
if (options_act() < 0) { /* acting on them failed. die. */
log_fn(LOG_ERR,"Acting on config options left us in a broken state. Dying.");
exit(1);
}
if (options_transition_affects_workers(lines)) {
log_fn(LOG_INFO,"Worker-related options changed. Rotating workers.");
cpuworkers_rotate();
dnsworkers_rotate();
}
config_free_lines(lines);
send_control_done(conn);
return 0;
}
......
......@@ -100,7 +100,8 @@ cpuworkers_rotate(void)
--num_cpuworkers;
}
last_rotation_time = time(NULL);
spawn_enough_cpuworkers();
if (server_mode(get_options()))
spawn_enough_cpuworkers();
}
/** If the cpuworker closes the connection,
......
......@@ -102,6 +102,7 @@ void
dns_init(void)
{
init_cache_tree();
dnsworkers_rotate();
}
/** Helper: free storage held by an entry in the DNS cache. */
......@@ -722,7 +723,8 @@ dnsworkers_rotate(void)
num_dnsworkers--;
}
last_rotation_time = time(NULL);
spawn_enough_dnsworkers();
if (server_mode(get_options()))
spawn_enough_dnsworkers();
}
/** Implementation for DNS workers; this code runs in a separate
......
......@@ -957,11 +957,7 @@ do_main_loop(void)
{
int loop_result;
dns_init(); /* initialize the dns resolve tree */
/* only spawn dns handlers if we're a router */
if (server_mode(get_options())) {
dnsworkers_rotate();
}
dns_init(); /* initialize dns resolve tree, spawn workers if needed */
handle_signals(1);
......
......@@ -1361,6 +1361,7 @@ void config_free_lines(config_line_t *front);
int options_trial_assign(config_line_t *list, int reset);
int resolve_my_address(or_options_t *options, uint32_t *addr);
void options_init(or_options_t *options);
int options_transition_affects_workers(config_line_t *lines);
int options_init_from_torrc(int argc, char **argv);
int options_init_logs(or_options_t *options, int validate_only);
int config_parse_addr_policy(config_line_t *cfg,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment