mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
stop putting wacky values into state->lastwritten
This commit is contained in:
parent
710227a77f
commit
df3cf881d1
5
changes/bug3039
Normal file
5
changes/bug3039
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
o Minor bugfixes:
|
||||||
|
- Write the current time into the LastWritten line in our state file,
|
||||||
|
rather than the time from the previous write attempt. Also, stop
|
||||||
|
trying to use a time of -1 in our log statements. Fixes bug 3039;
|
||||||
|
bugfix on 0.2.2.14-alpha.
|
@ -119,7 +119,7 @@ circuit_build_times_disabled(void)
|
|||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
int config_disabled = !get_options()->LearnCircuitBuildTimeout;
|
int config_disabled = !get_options()->LearnCircuitBuildTimeout;
|
||||||
int dirauth_disabled = get_options()->AuthoritativeDir;
|
int dirauth_disabled = get_options()->AuthoritativeDir;
|
||||||
int state_disabled = (get_or_state()->LastWritten == -1);
|
int state_disabled = did_last_state_file_write_fail() ? 1 : 0;
|
||||||
|
|
||||||
if (consensus_disabled || config_disabled || dirauth_disabled ||
|
if (consensus_disabled || config_disabled || dirauth_disabled ||
|
||||||
state_disabled) {
|
state_disabled) {
|
||||||
|
@ -5119,6 +5119,18 @@ or_state_load(void)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Did the last time we tried to write the state file fail? If so, we
|
||||||
|
* should consider disabling such features as preemptive circuit generation
|
||||||
|
* to compute circuit-build-time. */
|
||||||
|
static int last_state_file_write_failed = 0;
|
||||||
|
|
||||||
|
/** Return whether the state file failed to write last time we tried. */
|
||||||
|
int
|
||||||
|
did_last_state_file_write_fail(void)
|
||||||
|
{
|
||||||
|
return last_state_file_write_failed;
|
||||||
|
}
|
||||||
|
|
||||||
/** If writing the state to disk fails, try again after this many seconds. */
|
/** If writing the state to disk fails, try again after this many seconds. */
|
||||||
#define STATE_WRITE_RETRY_INTERVAL 3600
|
#define STATE_WRITE_RETRY_INTERVAL 3600
|
||||||
|
|
||||||
@ -5143,11 +5155,13 @@ or_state_save(time_t now)
|
|||||||
if (accounting_is_enabled(get_options()))
|
if (accounting_is_enabled(get_options()))
|
||||||
accounting_run_housekeeping(now);
|
accounting_run_housekeeping(now);
|
||||||
|
|
||||||
|
global_state->LastWritten = now;
|
||||||
|
|
||||||
tor_free(global_state->TorVersion);
|
tor_free(global_state->TorVersion);
|
||||||
tor_asprintf(&global_state->TorVersion, "Tor %s", get_version());
|
tor_asprintf(&global_state->TorVersion, "Tor %s", get_version());
|
||||||
|
|
||||||
state = config_dump(&state_format, global_state, 1, 0);
|
state = config_dump(&state_format, global_state, 1, 0);
|
||||||
format_local_iso_time(tbuf, time(NULL));
|
format_local_iso_time(tbuf, now);
|
||||||
tor_asprintf(&contents,
|
tor_asprintf(&contents,
|
||||||
"# Tor state file last generated on %s local time\n"
|
"# Tor state file last generated on %s local time\n"
|
||||||
"# Other times below are in GMT\n"
|
"# Other times below are in GMT\n"
|
||||||
@ -5158,7 +5172,7 @@ or_state_save(time_t now)
|
|||||||
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\"; "
|
log_warn(LD_FS, "Unable to write state to file \"%s\"; "
|
||||||
"will try again later", fname);
|
"will try again later", fname);
|
||||||
global_state->LastWritten = -1;
|
last_state_file_write_failed = 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
|
/* Try again after STATE_WRITE_RETRY_INTERVAL (or sooner, if the state
|
||||||
@ -5167,7 +5181,7 @@ or_state_save(time_t now)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
global_state->LastWritten = time(NULL);
|
last_state_file_write_failed = 0;
|
||||||
log_info(LD_GENERAL, "Saved state to \"%s\"", fname);
|
log_info(LD_GENERAL, "Saved state to \"%s\"", fname);
|
||||||
tor_free(fname);
|
tor_free(fname);
|
||||||
tor_free(contents);
|
tor_free(contents);
|
||||||
|
@ -58,6 +58,7 @@ char *options_get_datadir_fname2_suffix(or_options_t *options,
|
|||||||
get_datadir_fname2_suffix((sub1), NULL, (suffix))
|
get_datadir_fname2_suffix((sub1), NULL, (suffix))
|
||||||
|
|
||||||
or_state_t *get_or_state(void);
|
or_state_t *get_or_state(void);
|
||||||
|
int did_last_state_file_write_fail(void);
|
||||||
int or_state_save(time_t now);
|
int or_state_save(time_t now);
|
||||||
|
|
||||||
int options_need_geoip_info(or_options_t *options, const char **reason_out);
|
int options_need_geoip_info(or_options_t *options, const char **reason_out);
|
||||||
|
Loading…
Reference in New Issue
Block a user