repost: [Patch] Re: Time jumps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



repost for the thread [PATCH] time warp

---------- Forwarded message ----------
From: Sergei Haller <Sergei.Haller@xxxxxxxxxxxxxxxxxxx>
Organization: University of Giessen * Germany
To: VDR List <vdr@xxxxxxxxxxx>
Date: Thu, 2 Jan 2003 00:19:18 +0100 (CET)
Subject: [Patch] Re: Time jumps

[...]

Anyway, here is a small implementation of the cMJD::SetSystemTime()
method. This one just uses adjtime for small clock drifts and old
behaviour (jump) for bigger drifts.

(again, I'm sorry, but my vdr box is still broken, that's why I can't try
it out directly in vdr, but this function should cleanly fit in 1.1.20's
eit.c)

--------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>


/* these are for emulating vdr source only  */
#define bool  int
#define true  1
#define false 0
#define isyslog printf
#define esyslog printf
time_t mjdtime;



/* Note that adjtime speeds up or slows down the system clock by
   just 500 usec per second.
   That means, a difference of 1 second is done after ~33 minutes
   and a diff of 30 seconds after ~16.6 hours

   should this value become a setup parameter?
*/

#define MAXADJTIME 30 // seconds


/* this is a modified cMJD::SetSystemTime() from eit.c */
bool SetSystemTime(void)
{
   time_t loctim, diff;
   struct timeval delta;

   loctim = time(NULL); /* system time in seconds since epoch */
   diff = mjdtime - loctim;

   if ( abs(diff) > 0 ) {
      isyslog("System Time = %s (%ld)\n", ctime(&loctim),  loctim);
      isyslog("Local Time  = %s (%ld)\n", ctime(&mjdtime), mjdtime);
   }

   if ( abs(diff) > MAXADJTIME )
   {
      if (stime(&mjdtime) < 0)
         esyslog("ERROR while setting system time: %m\n");

      return true;
   }
   else if ( abs(diff) > 0 )
   {
      delta.tv_sec  = diff;
      delta.tv_usec = 0;

      if (adjtime(&delta, NULL) < 0)
         esyslog("ERROR while adjusting system time: %m\n");

      return true;
   }

   return false;
}

int main(void) {
     bool result;

     mjdtime = time(NULL) + 20 ; /* adjust the time by +20 seconds */
     result = SetSystemTime();

     return result;
}
--------------------------------------



c ya
        Sergei
-- 
--------------------------------------------------------------------  -?)
         eMail:       Sergei.Haller@xxxxxxxxxxxxxxxxxxx               /\\
-------------------------------------------------------------------- _\_V
Be careful of reading health books, you might die of a misprint.
                -- Mark Twain



[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux