aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2010-11-08 16:37:20 +0100
committerKarsten Loesing <karsten.loesing@gmx.net>2010-11-08 17:38:59 +0100
commited45bc198f10f5ea3dbd40514bb5b443802b50aa (patch)
tree75cc92580b7b94b09e733529709bd00cfb1ed759 /src
parent8c5ba9388bd372316cc18f23dcb6d41b4c1e9546 (diff)
downloadtor-ed45bc198f10f5ea3dbd40514bb5b443802b50aa.tar
tor-ed45bc198f10f5ea3dbd40514bb5b443802b50aa.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c30
1 files changed, 23 insertions, 7 deletions
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;