diff --git a/userspace/rootfs_override/etc/init.d/S70wr_date b/userspace/rootfs_override/etc/init.d/S70wr_date index 964ee7256a370a4c03615e52e0d045a32244f974..34a27e7f8bf24409b2245f9991c07ed5193bcaae 100755 --- a/userspace/rootfs_override/etc/init.d/S70wr_date +++ b/userspace/rootfs_override/etc/init.d/S70wr_date @@ -1,7 +1,10 @@ #!/bin/sh +# First of all, run wr_date, so to fix tai_offset in the kernel +/wr/bin/wr_date get > /dev/null + F=/wr/etc/wr_date.conf -# if there is no config file, do nothing. +# if there is no config file, do nothing else. test -f $F || exit 0 # pick the first server, if any diff --git a/userspace/tools/wr_date.c b/userspace/tools/wr_date.c index 52a6de8a2e7e060110885bc488318d475d16a8eb..e5e5350d578abcf176ce2ff2e2b96198dd671bae 100644 --- a/userspace/tools/wr_date.c +++ b/userspace/tools/wr_date.c @@ -167,7 +167,7 @@ int fix_host_tai(void) { struct timex t; char s[128]; - unsigned long long now, leapt, expire = 0; + unsigned long long now, now_2014, leapt, expire = 0; int i, *p, tai_offset = 0; /* first: get the current offset */ @@ -178,8 +178,22 @@ int fix_host_tai(void) return 0; } + /* + * At the very start, we believe to be Jan 1st 1970. But + * what we really want is counting the tai_offset, so WR + * can then set system time by itself. And, being wrong by + * 1-2 seconds is ok (system time is for log messages only), + * but being off by 35 seconds is not. So let's use "35" by + * default, i.e. be aware we are at least in 2014 + */ + now_2014 = 1417806803; /* as I write this */ + /* then, find the current time, using such offset */ - now = time(NULL) + 2208988800LL; /* (for TAI: + utc_offset) */ + now = time(NULL); + if (now < now_2014) + now = now_2014; + + now += 2208988800LL; /* (for TAI: + utc_offset) */ FILE *f = fopen(WRDATE_LEAP_FILE, "r"); if (!f) { @@ -192,7 +206,7 @@ int fix_host_tai(void) continue; if (sscanf(s, "%lli %i", &leapt, &i) != 2) continue; - /* check this line, and apply if if it's in the past */ + /* check this line, and apply it if it's in the past */ if (leapt < now) tai_offset = i; }