From bf1014692f9aea062f10df525ba39115ef890776 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 24 Dec 2006 03:06:03 +0000 Subject: r11686@Kushana: nickm | 2006-12-23 22:05:57 -0500 More changes wrt unnecessary disk writes. svn:r9176 --- src/or/hibernate.c | 6 +++++- src/or/router.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 65ad4c80f3..d7968f721a 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -544,6 +544,7 @@ accounting_record_bandwidth_usage(time_t now, or_state_t *state) time_t tmp; int r; uint64_t expected; + static time_t last_recorded; /* First, update bw_accounting. Until 0.1.2.5-x, this was the only place * we stored this information. The format is: @@ -572,7 +573,10 @@ accounting_record_bandwidth_usage(time_t now, or_state_t *state) (unsigned long)expected); tor_snprintf(fname, sizeof(fname), "%s/bw_accounting", get_options()->DataDirectory); - r = write_str_to_file(fname, buf, 0); + if (!get_options()->AvoidDiskWrites || (last_recorded + 3600 < now)) { + r = write_str_to_file(fname, buf, 0); + last_recorded = now; + } /* Now update the state */ state->AccountingIntervalStart = interval_start_time; diff --git a/src/or/router.c b/src/or/router.c index 350c9bd692..bc9485b18e 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -231,6 +231,7 @@ init_keys(void) const char *mydesc, *datadir; crypto_pk_env_t *prkey; char digest[20]; + char *cp; or_options_t *options = get_options(); or_state_t *state = get_or_state(); @@ -335,10 +336,17 @@ init_keys(void) log_err(LD_GENERAL,"Error writing fingerprint line"); return -1; } - if (write_str_to_file(keydir, fingerprint_line, 0)) { - log_err(LD_FS, "Error writing fingerprint line to file"); - return -1; + /* Check whether we need to write the fingerprint file. */ + cp = NULL; + if (file_status(keydir) == FN_FILE) + cp = read_str_to_file(keydir, 0, NULL); + if (!cp && strcmp(cp, fingerprint_line)) { + if (write_str_to_file(keydir, fingerprint_line, 0)) { + log_err(LD_FS, "Error writing fingerprint line to file"); + return -1; + } } + tor_free(cp); log(LOG_NOTICE, LD_GENERAL, "Your Tor server's identity key fingerprint is '%s %s'", -- cgit v1.2.3-54-g00ecf