-include time offsets in logging as well
authorChristian Grothoff <christian@grothoff.org>
Mon, 4 Mar 2013 04:53:31 +0000 (04:53 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 4 Mar 2013 04:53:31 +0000 (04:53 +0000)
src/include/gnunet_time_lib.h
src/util/common_logging.c
src/util/time.c

index d131e4eef4181d016df1ff83801968d2c100156d..660d15af9e552229f6d8be5d655bc06f5cbdd528 100644 (file)
@@ -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
index 000c33880538973d76af0c75ea9c2216c66c00af..cd845cccea3c54711bf2d1df1e6a5144f2ead009 100644 (file)
@@ -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)
     {
index b82a1ba7c794b18847eab142e3f94386d89009f4..825b7f8caad9a39a421972691c75dee76a5d5430 100644 (file)
@@ -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)).