Sfoglia il codice sorgente

Fix the dns bug: children weren't dying

We were telling a child to die by closing the parent's file descriptor
to him. But newer children were inheriting the open file descriptor from
the parent, and since they weren't closing them, the socket never closed,
so the child never read eof, so he never knew to exit.

As a side effect to this bug, we were probably failing to properly close
connections to remote hosts, ORs, and OPs, after a dns child was born.

I'm surprised Tor worked at all.


svn:r974
Roger Dingledine 22 anni fa
parent
commit
c485725c5a
4 ha cambiato i file con 13 aggiunte e 1 eliminazioni
  1. 9 0
      src/or/connection.c
  2. 1 0
      src/or/cpuworker.c
  3. 2 1
      src/or/dns.c
  4. 1 0
      src/or/or.h

+ 9 - 0
src/or/connection.c

@@ -128,6 +128,15 @@ void connection_free(connection_t *conn) {
   free(conn);
 }
 
+void connection_free_all(void) {
+  int i, n;
+  connection_t **carray;
+
+  get_connection_array(&carray,&n);
+  for(i=0;i<n;i++)
+    connection_free(carray[i]);
+}
+
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
   struct sockaddr_in bindaddr; /* where to bind */
   struct hostent *rent;

+ 1 - 0
src/or/cpuworker.c

@@ -126,6 +126,7 @@ int cpuworker_main(void *data) {
 
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
+  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
 
   for(;;) {
 

+ 2 - 1
src/or/dns.c

@@ -395,6 +395,7 @@ int dnsworker_main(void *data) {
 
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
+  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
 
   for(;;) {
 
@@ -506,7 +507,7 @@ static void spawn_enough_dnsworkers(void) {
     num_dnsworkers++;
   }
 
-  while(num_dnsworkers > num_dnsworkers_needed+MAX_IDLE_DNSWORKERS) { /* too many idle? */
+  while(num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) { /* too many idle? */
     /* cull excess workers */
     log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.",
            num_dnsworkers-num_dnsworkers_needed, num_dnsworkers);

+ 1 - 0
src/or/or.h

@@ -615,6 +615,7 @@ int getconfig(int argc, char **argv, or_options_t *options);
 
 connection_t *connection_new(int type);
 void connection_free(connection_t *conn);
+void connection_free_all(void);
 
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type);