diff options
author | Roger Dingledine <arma@torproject.org> | 2005-08-15 23:46:18 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2005-08-15 23:46:18 +0000 |
commit | 04d42ea4336c38dcb812757699513b4eaf89c95b (patch) | |
tree | 1b0ac34bf261092d4629378a87d14081d167bcc0 | |
parent | b1d3f124c46e954ef282c71586e34631e351c427 (diff) | |
download | tor-04d42ea4336c38dcb812757699513b4eaf89c95b.tar tor-04d42ea4336c38dcb812757699513b4eaf89c95b.tar.gz |
rotate dns and cpu workers if the controller changes options that
will affect them.
svn:r4787
-rw-r--r-- | src/or/config.c | 20 | ||||
-rw-r--r-- | src/or/control.c | 7 | ||||
-rw-r--r-- | src/or/cpuworker.c | 3 | ||||
-rw-r--r-- | src/or/dns.c | 4 | ||||
-rw-r--r-- | src/or/main.c | 6 | ||||
-rw-r--r-- | src/or/or.h | 1 |
6 files changed, 33 insertions, 8 deletions
diff --git a/src/or/config.c b/src/or/config.c index 1363d8566..c40a2c6b3 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -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. */ diff --git a/src/or/control.c b/src/or/control.c index 5c1fbc566..609d1f860 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -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; } diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index d1c0f0e04..397aa3669 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -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, diff --git a/src/or/dns.c b/src/or/dns.c index 21ff68924..39ce5ff1c 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -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 diff --git a/src/or/main.c b/src/or/main.c index e33b19c8e..f6080c761 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -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); diff --git a/src/or/or.h b/src/or/or.h index af8bcecc5..590480bc9 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -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, |