VxWorks: Re-run tz2timezone() whenever the year increases

In the event that it then goes backwards we won't run it again; that
should never happen, but if it did we should prefer stability!
This commit is contained in:
Andrew Johnson
2022-06-16 14:38:46 -05:00
committed by Michael Davidsaver
parent 87d5c01853
commit bf0b4d2f61
+16 -3
View File
@@ -39,8 +39,21 @@ static CLOCKTIME_SYNCHOOK prevHook;
extern char* sysBootLine;
static void timeSync(int synchronized) {
if (!tz2timezone())
ClockTime_syncHook = prevHook; /* Don't call me again */
if (prevHook)
prevHook(synchronized);
if (synchronized) {
struct timespec tsNow;
if (clock_gettime(CLOCK_REALTIME, &tsNow) != OK)
return;
struct tm tmNow;
localtime_r(&tsNow.tv_sec, &tmNow);
static int lastYear = 0;
if (tmNow.tm_year > lastYear && !tz2timezone())
lastYear = tmNow.tm_year;
}
}
static int timeRegister(void)
@@ -52,7 +65,7 @@ static int timeRegister(void)
if (tz && *tz) {
epicsEnvSet("TZ", tz);
/* Call tz2timezone() once we know what year it is */
/* Call tz2timezone() from the sync thread, needs the year */
prevHook = ClockTime_syncHook;
ClockTime_syncHook = timeSync;
}