Browse Source

Merge branch 'bug2346' into maint-0.2.2

Nick Mathewson 14 years ago
parent
commit
597433bcec
2 changed files with 14 additions and 1 deletions
  1. 6 0
      changes/bug2346
  2. 8 1
      src/or/config.c

+ 6 - 0
changes/bug2346

@@ -0,0 +1,6 @@
+  o Minor features
+    - If writing the state file to disk fails, wait up to an hour
+      before retrying again.  (Our old code would retry the write
+      immediately.)  Fixes bug 2346.  Bugfix on Tor 0.1.1.3-alpha.
+
+

+ 8 - 1
src/or/config.c

@@ -5145,6 +5145,9 @@ or_state_load(void)
   return r;
   return r;
 }
 }
 
 
+/** If writing the state to disk fails, try again after this many seconds. */
+#define STATE_WRITE_RETRY_INTERVAL 3600
+
 /** Write the persistent state to disk. Return 0 for success, <0 on failure. */
 /** Write the persistent state to disk. Return 0 for success, <0 on failure. */
 int
 int
 or_state_save(time_t now)
 or_state_save(time_t now)
@@ -5179,10 +5182,14 @@ or_state_save(time_t now)
   tor_free(state);
   tor_free(state);
   fname = get_datadir_fname("state");
   fname = get_datadir_fname("state");
   if (write_str_to_file(fname, contents, 0)<0) {
   if (write_str_to_file(fname, contents, 0)<0) {
-    log_warn(LD_FS, "Unable to write state to file \"%s\"", fname);
+    log_warn(LD_FS, "Unable to write state to file \"%s\"; will try later",
+             fname);
     global_state->LastWritten = -1;
     global_state->LastWritten = -1;
     tor_free(fname);
     tor_free(fname);
     tor_free(contents);
     tor_free(contents);
+    /* Try again after STATE_WRITE_RETRY_INTERVAL (or sooner, if the state
+     * changes sooner). */
+    global_state->next_write = now + STATE_WRITE_RETRY_INTERVAL;
     return -1;
     return -1;
   }
   }