diff -r -U4 ntp-stable-4.2.0a-20040617/libntp/systime.c ntp-stable-4.2.0a-20040617_sa/libntp/systime.c --- ntp-stable-4.2.0a-20040617/libntp/systime.c 2004-05-25 12:02:24.000000000 +0100 +++ ntp-stable-4.2.0a-20040617_sa/libntp/systime.c 2009-01-13 16:26:10.000000000 +0000 @@ -8,8 +8,14 @@ #include "ntp_fp.h" #include "ntp_syslog.h" #include "ntp_unixtime.h" #include "ntp_stdlib.h" +#include +#include +#include +#include +#include +#include #ifdef SIM #include "ntpsim.h" #endif /*SIM */ @@ -43,8 +49,43 @@ double sys_tick = 1e-6; /* 1 us tickadj() */ #endif double sys_residual = 0; /* adjustment residue (s) */ +static int sys_offset_read = 0; +static long sys_offset; +long get_sysoffset(void) { + int fd; + if (!sys_offset_read) { + errno = 0; + fd = open("/etc/ntpoffset", O_RDONLY); + if (fd >= 0) { + char buf[51]; + long tmp; + int count = read(fd, buf, 50); + if (count > 0 && count < 50) { + buf[51] = 0; + errno = 0; + tmp = strtol(buf, (char **)NULL, 10); + if (errno == 0) { + sys_offset = tmp; + sys_offset_read = 1; + } else { + msyslog(LOG_ERR, "/etc/ntpoffset error(strtol): value=%ld errno=%d", tmp, errno); + } + } else { + msyslog(LOG_ERR, "/etc/ntpoffset error(read): read=%d errno=%d", count, errno); + } + close(fd); + } else if (errno == 2) { + sys_offset = 0; + sys_offset_read = 1; + } else { + msyslog(LOG_ERR, "/etc/ntpoffset error(open): errno=%d", errno); + } + } + return sys_offset; +} + #ifndef SIM /* * get_systime - return system time in NTP timestamp format. @@ -81,8 +122,10 @@ dtemp = tv.tv_usec / 1e6; #endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ + now->l_i -= get_sysoffset(); + /* * Renormalize to seconds past 1900 and fraction. */ dtemp += sys_residual; @@ -112,8 +155,10 @@ double dtemp; long ticks; int isneg = 0; + now += get_sysoffset(); + /* * Most Unix adjtime() implementations adjust the system clock * in microsecond quanta, but some adjust in 10-ms quanta. We * carefully round the adjustment to the nearest quantum, then @@ -166,8 +211,10 @@ #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) struct timespec ts; #endif + now += get_sysoffset(); + dtemp = sys_residual + now; if (dtemp < 0) { isneg = 1; dtemp = - dtemp; @@ -190,8 +237,9 @@ #else /* not HAVE_GETCLOCK */ (void) GETTIMEOFDAY(&timetv, (struct timezone *)0); #endif /* not HAVE_GETCLOCK */ + timetv.tv_sec -= get_sysoffset(); oldtimetv = timetv; #ifdef DEBUG if (debug)