From: Christian Grothoff Date: Mon, 4 Mar 2013 04:53:31 +0000 (+0000) Subject: -include time offsets in logging as well X-Git-Tag: initial-import-from-subversion-38251~9777 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=429d914cdd3dd4eb662c0ca85fa3de77b26e15cc;p=oweals%2Fgnunet.git -include time offsets in logging as well --- diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index d131e4eef..660d15af9 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -465,6 +465,15 @@ void GNUNET_TIME_set_offset (long long offset); +/** + * Get the timestamp offset for this instance. + * + * @return the offset we currently skew the locale time by + */ +long long +GNUNET_TIME_get_offset (void); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 000c33880..cd845ccce 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -886,11 +886,14 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, memset (date, 0, DATE_STR_SIZE); { char buf[size]; + long long offset; #ifdef WINDOWS LARGE_INTEGER pc; time_t timetmp; + offset = GNUNET_TIME_get_offset (); time (&timetmp); + timetmp += offset / 1000; tmptr = localtime (&timetmp); pc.QuadPart = 0; QueryPerformanceCounter (&pc); @@ -909,6 +912,30 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, struct timeval timeofday; gettimeofday (&timeofday, NULL); + offset = GNUNET_TIME_get_offset (); + if (offset > 0) + { + timeofday.tv_sec += offset / 1000LL; + timeofday.tv_usec += (offset % 1000LL) * 1000LL; + if (timeofday.tv_usec > 1000000LL) + { + timeofday.tv_usec -= 1000000LL; + timeofday.tv_sec++; + } + } + else + { + timeofday.tv_sec += offset / 1000LL; + if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL) + { + timeofday.tv_usec += (offset % 1000LL) * 1000LL; + } + else + { + timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; + timeofday.tv_sec--; + } + } tmptr = localtime (&timeofday.tv_sec); if (NULL == tmptr) { diff --git a/src/util/time.c b/src/util/time.c index b82a1ba7c..825b7f8ca 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -45,6 +45,18 @@ GNUNET_TIME_set_offset (long long offset) } +/** + * Get the timestamp offset for this instance. + * + * @return the offset we currently skew the locale time by + */ +long long +GNUNET_TIME_get_offset () +{ + return timestamp_offset; +} + + /** * Get the current time (works just as "time", just that we use the * unit of time that the cron-jobs use (and is 64 bit)).