[or-cvs] on hup, close and rebind listener ports too (in case their ...

Roger Dingledine arma at seul.org
Sun Dec 14 06:03:49 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	connection.c cpuworker.c dirserv.c main.c 
Log Message:
on hup, close and rebind listener ports too (in case their config has changed)


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- connection.c	9 Dec 2003 01:04:11 -0000	1.138
+++ connection.c	14 Dec 2003 06:03:46 -0000	1.139
@@ -289,6 +289,15 @@
   return 1;
 }
 
+static void listener_close_if_present(int type) {
+  connection_t *conn = connection_get_by_type(type);
+  if (conn) {
+    close(conn->s);
+    conn->s = -1;
+    conn->marked_for_close = 1;
+  }
+}
+
 /* start all connections that should be up but aren't */
 int retry_all_connections(void) {
 
@@ -296,19 +305,22 @@
     router_retry_connections();
   }
 
-  if(options.ORPort && !connection_get_by_type(CONN_TYPE_OR_LISTENER)) {
+  if(options.ORPort) {
+    listener_close_if_present(CONN_TYPE_OR_LISTENER);
     if(connection_create_listener(options.ORBindAddress, options.ORPort,
                                   CONN_TYPE_OR_LISTENER) < 0)
       return -1;
   }
 
-  if(options.DirPort && !connection_get_by_type(CONN_TYPE_DIR_LISTENER)) {
+  if(options.DirPort) {
+    listener_close_if_present(CONN_TYPE_DIR_LISTENER);
     if(connection_create_listener(options.DirBindAddress, options.DirPort,
                                   CONN_TYPE_DIR_LISTENER) < 0)
       return -1;
   }
- 
-  if(options.SocksPort && !connection_get_by_type(CONN_TYPE_AP_LISTENER)) {
+
+  if(options.SocksPort) {
+    listener_close_if_present(CONN_TYPE_AP_LISTENER);
     if(connection_create_listener(options.SocksBindAddress, options.SocksPort,
                                   CONN_TYPE_AP_LISTENER) < 0)
       return -1;

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cpuworker.c	16 Nov 2003 17:00:02 -0000	1.15
+++ cpuworker.c	14 Dec 2003 06:03:46 -0000	1.16
@@ -58,7 +58,7 @@
   assert(conn && conn->type == CONN_TYPE_CPUWORKER);
 
   if(conn->inbuf_reached_eof) {
-    log_fn(LOG_WARN,"Read eof. Worker dying.");
+    log_fn(LOG_WARN,"Read eof. Worker has died.");
     if(conn->state != CPUWORKER_STATE_IDLE) {
       /* the circ associated with this cpuworker will have to wait until
        * it gets culled in run_connection_housekeeping(), since we have

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- dirserv.c	14 Dec 2003 05:25:23 -0000	1.21
+++ dirserv.c	14 Dec 2003 06:03:46 -0000	1.22
@@ -52,7 +52,7 @@
 }
 
 /* return 0 on success, -1 on failure */
-int 
+int
 dirserv_parse_fingerprint_file(const char *fname)
 {
   FILE *file;
@@ -172,7 +172,7 @@
   free(desc);
 }
 
-void 
+void
 dirserv_free_descriptors()
 {
   int i;
@@ -311,7 +311,7 @@
   return 0;
 }
 
-static int 
+static int
 list_running_servers(char **nicknames_out)
 {
   char *nickname_lst[MAX_ROUTERS_IN_DIR];
@@ -323,7 +323,7 @@
   int length;
   *nicknames_out = NULL;
   nickname_lst[n++] = options.Nickname;
-  
+
   get_connection_array(&connection_array, &n_conns);
   for (i = 0; i<n_conns; ++i) {
     conn = connection_array[i];
@@ -349,7 +349,6 @@
   return 0;
 }
 
-
 int
 dirserv_dump_directory_to_string(char *s, int maxlen,
                                  crypto_pk_env_t *private_key)
@@ -400,8 +399,7 @@
       ((int)digest[0])&0xff,((int)digest[1])&0xff,
       ((int)digest[2])&0xff,((int)digest[3])&0xff);
 
-  strncpy(cp, 
-          "-----BEGIN SIGNATURE-----\n", maxlen-i);
+  strncpy(cp, "-----BEGIN SIGNATURE-----\n", maxlen-i);
 
   i = strlen(s);
   cp = s+i;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -d -r1.157 -r1.158
--- main.c	14 Dec 2003 04:39:23 -0000	1.157
+++ main.c	14 Dec 2003 06:03:46 -0000	1.158
@@ -481,8 +481,9 @@
         /* no need to provide argc/v, they've been cached inside init_from_config */
         exit(1);
       }
-      if(options.ORPort) {
-        router_retry_connections();
+      if(retry_all_connections() < 0) {
+        log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
+        return -1;
       }
       if(options.DirPort) {
         /* reload the fingerprint file */



More information about the tor-commits mailing list