[or-cvs] catch hup to reload directory/router list

Roger Dingledine arma at seul.org
Sat Sep 28 01:40:14 UTC 2002


Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or

Modified Files:
	main.c or.h 
Log Message:
catch hup to reload directory/router list


Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- main.c	28 Sep 2002 00:52:59 -0000	1.27
+++ main.c	28 Sep 2002 01:40:11 -0000	1.28
@@ -17,6 +17,7 @@
 static int nfds=0; /* number of connections currently active */
 
 static int please_dumpstats=0; /* whether we should dump stats during the loop */
+static int please_fetch_directory=0; /* whether we should fetch a new directory */
 
 /* private key */
 static crypto_pk_env_t *privatekey;
@@ -438,6 +439,17 @@
   for(;;) {
     if(please_dumpstats) {
       dumpstats();
+      please_dumpstats = 0;
+    }
+    if(please_fetch_directory) {
+      if(options.Role & ROLE_DIR_SERVER) {
+        if(router_get_list_from_file(options.RouterFile, options.ORPort) < 0) {
+          log(LOG_ERR,"Error reloading router list. Continuing with old list.");
+        }
+      } else {
+        directory_initiate_fetch(router_pick_directory_server());
+      }
+      please_fetch_directory = 0;
     }
     if(prepare_for_poll(&timeout) < 0) {
       log(LOG_DEBUG,"do_main_loop(): prepare_for_poll failed, exiting.");
@@ -483,16 +495,23 @@
   }
 }
 
-void catchint () {
-  errno = 0; /* netcat does this. it looks fun. */
-
-  log(LOG_NOTICE,"Catching ^c, exiting cleanly.");
-   
-  exit(0);
-}
+static void catch(int the_signal) {
 
-void catchusr1 () {
-  please_dumpstats = 1;
+  switch(the_signal) {
+    case SIGABRT:
+    case SIGTERM:
+    case SIGINT:
+      log(LOG_NOTICE,"Catching signal %d, exiting cleanly.", the_signal);
+      exit(0);
+    case SIGHUP:
+      please_fetch_directory = 1;
+      break;
+    case SIGUSR1:
+      please_dumpstats = 1;
+      break;
+    default:
+      log(LOG_ERR,"Caught signal that we can't handle??");
+  }
 }
 
 void dumpstats (void) { /* dump stats to stdout */
@@ -515,7 +534,6 @@
     printf("\n");
   }
 
-  please_dumpstats = 0;
 }
 
 int dump_router_to_string(char *s, int maxlen, routerinfo_t *router) {
@@ -583,8 +601,11 @@
 int main(int argc, char *argv[]) {
   int retval = 0;
 
-  signal (SIGINT, catchint); /* to catch ^c so we can exit cleanly */
-  signal (SIGUSR1, catchusr1); /* to dump stats to stdout */
+  signal (SIGINT, catch); /* catch kills so we can exit cleanly */
+  signal (SIGABRT, catch);
+  signal (SIGTERM, catch);
+  signal (SIGUSR1, catch); /* to dump stats to stdout */
+  signal (SIGHUP, catch); /* to reload directory */
 
   if ( getoptions(argc,argv,&options) ) exit(1);
   log(options.loglevel,NULL);         /* assign logging severity level from options */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- or.h	28 Sep 2002 00:52:59 -0000	1.29
+++ or.h	28 Sep 2002 01:40:11 -0000	1.30
@@ -602,8 +602,6 @@
 
 int do_main_loop(void);
 
-void catchint();
-void catchusr1();
 void dumpstats(void);
 void dump_directory_to_string(char *s, int maxlen);
 



More information about the tor-commits mailing list