[or-cvs] Resolve some hibernating-related XXXX009s.

Nick Mathewson nickm at seul.org
Sun Nov 14 22:21:25 UTC 2004


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

Modified Files:
	config.c hibernate.c main.c or.h 
Log Message:
Resolve some hibernating-related XXXX009s.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.252
retrieving revision 1.253
diff -u -d -r1.252 -r1.253
--- config.c	14 Nov 2004 20:51:28 -0000	1.252
+++ config.c	14 Nov 2004 22:21:22 -0000	1.253
@@ -310,6 +310,10 @@
     return -1;
   }
 
+  /* Set up accounting */
+  if (get_options()->AccountingMaxKB)
+    configure_accounting(time(NULL));
+
   if(retry_all_listeners(1) < 0) {
     log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
     return -1;

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- hibernate.c	14 Nov 2004 21:11:06 -0000	1.18
+++ hibernate.c	14 Nov 2004 22:21:22 -0000	1.19
@@ -83,7 +83,6 @@
 
 static void reset_accounting(time_t now);
 static int read_bandwidth_usage(void);
-static int record_bandwidth_usage(time_t now);
 static time_t start_of_accounting_period_after(time_t now);
 static time_t start_of_accounting_period_containing(time_t now);
 static void accounting_set_wakeup_time(void);
@@ -316,12 +315,11 @@
          (int)(unsigned char)digest[0], buf);
 }
 
-/* XXXX009 This should also get called on HUP and shutdown. */
 #define BW_ACCOUNTING_VERSION 1
 /** Save all our bandwidth tracking information to disk. Return 0 on
  * success, -1 on failure*/
-static int
-record_bandwidth_usage(time_t now)
+int
+accounting_record_bandwidth_usage(time_t now)
 {
   char buf[128];
   char fname[512];
@@ -483,7 +481,7 @@
   }
 
   hibernate_state = new_state;
-  record_bandwidth_usage(time(NULL));
+  accounting_record_bandwidth_usage(now);
 }
 
 /** Called when we've been hibernating and our timeout is reached. */
@@ -539,7 +537,7 @@
     connection_mark_for_close(conn);
   }
 
-  record_bandwidth_usage(time(NULL));
+  accounting_record_bandwidth_usage(now);
 }
 
 /** Called when hibernate_end_time has arrived. */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.373
retrieving revision 1.374
diff -u -d -r1.373 -r1.374
--- main.c	14 Nov 2004 21:46:40 -0000	1.373
+++ main.c	14 Nov 2004 22:21:22 -0000	1.374
@@ -737,6 +737,8 @@
 
   log_fn(LOG_NOTICE,"Received sighup. Reloading config.");
   has_completed_circuit=0;
+  accounting_record_bandwidth_usage();
+
   /* 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) {
@@ -793,11 +795,6 @@
   stats_prev_global_read_bucket = global_read_bucket;
   stats_prev_global_write_bucket = global_write_bucket;
 
-  /*XXX009 move to options_act? */
-  /* Set up accounting */
-  if (get_options()->AccountingMaxKB)
-    configure_accounting(time(NULL));
-
   /* load the routers file, or assign the defaults. */
   if(router_reload_router_list()) {
     return -1;
@@ -1082,6 +1079,7 @@
   if(options->PidFile && options->command == CMD_RUN_TOR)
     unlink(options->PidFile);
   crypto_global_cleanup();
+  accounting_record_bandwidth_usage();
 }
 
 /** Read/create keys as needed, and echo our fingerprint to stdout. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.482
retrieving revision 1.483
diff -u -d -r1.482 -r1.483
--- or.h	14 Nov 2004 20:51:28 -0000	1.482
+++ or.h	14 Nov 2004 22:21:23 -0000	1.483
@@ -1327,6 +1327,7 @@
 void configure_accounting(time_t now);
 void accounting_run_housekeeping(time_t now);
 void accounting_add_bytes(size_t n_read, size_t n_written, int seconds);
+int accounting_record_bandwidth_usage(time_t now);
 void hibernate_begin_shutdown(void);
 int we_are_hibernating(void);
 void consider_hibernation(time_t now);



More information about the tor-commits mailing list