[or-cvs] Rotate dnsworkers and cpuworkers on SIGHUP, so they get new...

Nick Mathewson nickm at seul.org
Sun Jun 6 03:38:33 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv27849/src/or

Modified Files:
	dns.c main.c 
Log Message:
Rotate dnsworkers and cpuworkers on SIGHUP, so they get new config settings too

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- dns.c	2 Jun 2004 18:32:24 -0000	1.98
+++ dns.c	6 Jun 2004 03:38:31 -0000	1.99
@@ -35,9 +35,11 @@
 #define DNS_RESOLVE_SUCCEEDED 3
 
 /** How many dnsworkers we have running right now. */
-int num_dnsworkers=0;
+static int num_dnsworkers=0;
 /** How many of the running dnsworkers have an assigned task right now. */
-int num_dnsworkers_busy=0;
+static int num_dnsworkers_busy=0;
+/** When did we last rotate the dnsworkers? */
+static time_t last_rotation_time=0;
 
 /** Linked list of connections waiting for a DNS answer. */
 struct pending_connection_t {
@@ -92,6 +94,7 @@
 /** Initialize the DNS subsystem; called by the OR process. */
 void dns_init(void) {
   init_cache_tree();
+  last_rotation_time=time(NULL);
   spawn_enough_dnsworkers();
 }
 
@@ -535,10 +538,29 @@
   conn->address = tor_strdup("<idle>");
   conn->state = DNSWORKER_STATE_IDLE;
   num_dnsworkers_busy--;
-
+  if (conn->timestamp_created < last_rotation_time) {
+    connection_mark_for_close(conn);
+    num_dnsworkers--;
+    spawn_enough_dnsworkers();
+  }
   return 0;
 }
 
+/** Close and re-open all idle dnsworkers; schedule busy ones to be closed
+ * and re-opened once they're no longer busy.
+ **/
+void dnsworkers_rotate(void)
+{
+  connection_t *dnsconn;
+  while ((dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER,
+                                                 DNSWORKER_STATE_IDLE))) {
+    connection_mark_for_close(dnsconn);
+    num_dnsworkers--;
+  }
+  last_rotation_time = time(NULL);
+  spawn_enough_dnsworkers();
+}
+
 /** Implementation for DNS workers; this code runs in a separate
  * execution context.  It takes as its argument an fdarray as returned
  * by socketpair(), and communicates via fdarray[1].  The protocol is

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -d -r1.280 -r1.281
--- main.c	2 Jun 2004 19:18:37 -0000	1.280
+++ main.c	6 Jun 2004 03:38:31 -0000	1.281
@@ -638,6 +638,11 @@
     directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 0);
   }
   if(options.ORPort) {
+    /* Restart cpuworker and dnsworker processes, so they get up-to-date
+     * configuration options. */
+    cpuworkers_rotate();
+    dnsworkers_rotate();
+    /* Rebuild fresh descriptor as needed. */
     router_rebuild_descriptor();
     sprintf(keydir,"%s/router.desc", options.DataDirectory);
     log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);



More information about the tor-commits mailing list