[or-cvs] break out the operations done on sighup into their own func...

Roger Dingledine arma at seul.org
Thu Feb 26 22:30:46 UTC 2004


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

Modified Files:
	main.c 
Log Message:
break out the operations done on sighup into their own function


Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- main.c	26 Feb 2004 22:20:00 -0000	1.170
+++ main.c	26 Feb 2004 22:30:44 -0000	1.171
@@ -446,6 +446,41 @@
   return 0;
 }
 
+static int do_hup(void) {
+  char keydir[512];
+
+  log_fn(LOG_WARN,"Received sighup. Reloading config.");
+  /* first, reload config variables, in case they've changed */
+  /* no need to provide argc/v, they've been cached inside init_from_config */
+  if (init_from_config(0, NULL) < 0) {
+    exit(1);
+  }
+  if(retry_all_connections() < 0) {
+    log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
+    return -1;
+  }
+  if(options.DirPort) {
+    /* reload the approved-routers file */
+    sprintf(keydir,"%s/approved-routers", options.DataDirectory);
+    log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir);
+    if(dirserv_parse_fingerprint_file(keydir) < 0) {
+      log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list.");
+    }
+  } else {
+    /* fetch a new directory */
+    directory_initiate_command(router_pick_directory_server(), DIR_CONN_STATE_CONNECTING_FETCH);
+  }
+  if(options.ORPort) {
+    router_rebuild_descriptor();
+    sprintf(keydir,"%s/router.desc", options.DataDirectory);
+    log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
+    if (write_str_to_file(keydir, router_get_my_descriptor())) {
+      return -1;
+    }
+  }
+  return 0;
+}
+
 static int do_main_loop(void) {
   int i;
   int timeout;
@@ -487,36 +522,7 @@
       please_dumpstats = 0;
     }
     if(please_reset) {
-      char keydir[512];
-      log_fn(LOG_WARN,"Received sighup. Reloading config.");
-      /* first, reload config variables, in case they've changed */
-      /* no need to provide argc/v, they've been cached inside init_from_config */
-      if (init_from_config(0, NULL) < 0) {
-        exit(1);
-      }
-      if(retry_all_connections() < 0) {
-        log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
-        return -1;
-      }
-      if(options.DirPort) {
-        /* reload the approved-routers file */
-        sprintf(keydir,"%s/approved-routers", options.DataDirectory);
-        log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir);
-        if(dirserv_parse_fingerprint_file(keydir) < 0) {
-          log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list.");
-        }
-      } else {
-        /* fetch a new directory */
-        directory_initiate_command(router_pick_directory_server(), DIR_CONN_STATE_CONNECTING_FETCH);
-      }
-      if(options.ORPort) {
-        router_rebuild_descriptor();
-        sprintf(keydir,"%s/router.desc", options.DataDirectory);
-        log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
-        if (write_str_to_file(keydir, router_get_my_descriptor())) {
-          return -1;
-        }
-
+      do_hup();
       please_reset = 0;
     }
     if(please_reap_children) {



More information about the tor-commits mailing list