From ed45bc198f10f5ea3dbd40514bb5b443802b50aa Mon Sep 17 00:00:00 2001 From: Karsten Loesing Date: Mon, 8 Nov 2010 16:37:20 +0100 Subject: Fix log granularity based on Nick's comments. Instead of rejecting a value that doesn't divide into 1 second, round to the nearest divisor of 1 second and warn. Document that the option only controls the granularity written by Tor to a file or console log. It does not (for example) "batch up" log messages to affect times logged by a controller, times attached to syslog messages, or the mtime fields on log files. --- src/or/config.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/or/config.c b/src/or/config.c index 111247894..0251ef49d 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4342,15 +4342,31 @@ options_init_logs(or_options_t *options, int validate_only) options->RunAsDaemon; #endif - if (options->LogTimeGranularity > 0 && - (1000 % options->LogTimeGranularity == 0 || - options->LogTimeGranularity % 1000 == 0)) { - set_log_time_granularity(options->LogTimeGranularity); - } else { - log_warn(LD_CONFIG, "Log time granularity '%d' has to be positive " - "and either a divisor or a multiple of 1 second.", + if (options->LogTimeGranularity <= 0) { + log_warn(LD_CONFIG, "Log time granularity '%d' has to be positive.", options->LogTimeGranularity); return -1; + } else if (1000 % options->LogTimeGranularity != 0 && + options->LogTimeGranularity % 1000 != 0) { + int granularity = options->LogTimeGranularity; + if (granularity < 40) { + do granularity++; + while (1000 % granularity != 0); + } else if (granularity < 1000) { + granularity = 1000 / granularity; + while (1000 % granularity != 0) + granularity--; + granularity = 1000 / granularity; + } else { + granularity = 1000 * ((granularity / 1000) + 1); + } + log_warn(LD_CONFIG, "Log time granularity '%d' has to be either a " + "divisor or a multiple of 1 second. Changing to " + "'%d'.", + options->LogTimeGranularity, granularity); + set_log_time_granularity(granularity); + } else { + set_log_time_granularity(options->LogTimeGranularity); } ok = 1; -- cgit v1.2.3