From: Roger Dingledine Date: Mon, 15 Nov 2004 04:01:31 +0000 (+0000) Subject: fix a bug in configuring accounting in options_act() X-Git-Tag: tor-0.0.9pre6~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee591be3f2743d31f1ac5c7d2de74adb773fbec9;p=thirdparty%2Ftor.git fix a bug in configuring accounting in options_act() svn:r2881 --- diff --git a/src/or/config.c b/src/or/config.c index 95e0308fdc..22dc29ed76 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -311,7 +311,7 @@ options_act(void) { } /* Set up accounting */ - if (get_options()->AccountingMaxKB) + if (accounting_is_enabled(options)) configure_accounting(time(NULL)); if(retry_all_listeners(1) < 0) { diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 7667a8a230..f972479246 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -91,6 +91,15 @@ static void accounting_set_wakeup_time(void); * Functions for bandwidth accounting. * ************/ +/** If we want to manage the accounting system and potentially + * hibernate, return 1, else return 0. + */ +int accounting_is_enabled(or_options_t *options) { + if (options->AccountingMaxKB) + return 1; + return 0; +} + /** Called from main.c to tell us that seconds seconds have * passed, n_read bytes have been read, and n_written * bytes have been written. */ diff --git a/src/or/main.c b/src/or/main.c index f07641385e..81e32fe700 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -556,7 +556,7 @@ static void run_scheduled_events(time_t now) { /** 1c. If we have to change the accounting interval or record * bandwidth used in this accounting interval, do so. */ - if (options->AccountingMaxKB) + if (accounting_is_enabled(options)) accounting_run_housekeeping(now); /** 2. Every DirFetchPostPeriod seconds, we get a new directory and @@ -700,7 +700,7 @@ static int prepare_for_poll(void) { seconds_elapsed = current_second ? (now.tv_sec - current_second) : 0; stats_n_bytes_read += bytes_read; stats_n_bytes_written += bytes_written; - if (get_options()->AccountingMaxKB) + if (accounting_is_enabled(get_options())) accounting_add_bytes(bytes_read, bytes_written, seconds_elapsed); control_event_bandwidth_used((uint32_t)bytes_read,(uint32_t)bytes_written); diff --git a/src/or/or.h b/src/or/or.h index 35cc304a17..72fa6f80aa 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1324,6 +1324,7 @@ int dns_resolve(connection_t *exitconn); /********************************* hibernate.c **********************/ +int accounting_is_enabled(or_options_t *options); 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);