소스 검색

rotate dns and cpu workers if the controller changes options that
will affect them.


svn:r4787

Roger Dingledine 19 년 전
부모
커밋
04d42ea433
6개의 변경된 파일33개의 추가작업 그리고 8개의 파일을 삭제
  1. 20 0
      src/or/config.c
  2. 6 1
      src/or/control.c
  3. 2 1
      src/or/cpuworker.c
  4. 3 1
      src/or/dns.c
  5. 1 5
      src/or/main.c
  6. 1 0
      src/or/or.h

+ 20 - 0
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. */

+ 6 - 1
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;
 }

+ 2 - 1
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,

+ 3 - 1
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

+ 1 - 5
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);
 

+ 1 - 0
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,