[tor-commits] [torsocks/master] Use seconds since epoch, not local time, for log timestamps.

dgoulet at torproject.org dgoulet at torproject.org
Mon Jun 13 21:14:03 UTC 2016


commit 35187508cfaf3fd21ed68159f4635ee2d376aea4
Author: Taylor R Campbell <campbell+torsocks at mumble.net>
Date:   Fri Jun 19 04:23:36 2015 +0000

    Use seconds since epoch, not local time, for log timestamps.
    
    Local time may require opening files to load the time zone database, which
    leads to a potential deadlock-against-self when intercepting a close() in the
    middle of tsocks_once initialization for close().
    
    The same issue applies even if we use UTC, via gmtime.
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/common/log.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index b68d66b..8bf8836 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -47,14 +47,12 @@ int tsocks_loglevel = DEFAULT_LOG_LEVEL;
 static size_t add_time_to_log(char *buf, size_t len)
 {
 	time_t now;
-	const struct tm *tm;
 
 	assert(buf);
 
 	/* Get time stamp. */
 	time(&now);
-	tm = localtime(&now);
-	return strftime(buf, len, "[%b %d %H:%M:%S] ", tm);
+	return snprintf(buf, len, "%llu ", (unsigned long long)now);
 }
 
 /*





More information about the tor-commits mailing list