Commit 0098a6bb authored by Alessandro Rubini's avatar Alessandro Rubini

userspace: fix wr_date to mark tai_offset even at startup

Also, run "wr_date get" at boot once, so it parses leap-seconds.list
and configures the kernel for the proper tai_offset.

With the previous commit it worked with "wr_date get tohost",
becase after the host is correctly in 2014 or so, all leap seconds are
in the past.  But if we are not synced, the host is in 1970 and
no leap second has already happened.

If this code is unchanged in 2018, we'd better be off by 2 seconds
than 37, so if linux reports a date earlier than 2014, use 2014 and
fix tai_offset at 35.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 9c1c52dc
#!/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
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment