From bf0b4d2f61e1adabb642c9184d5835dc67231e42 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 16 Jun 2022 14:38:46 -0500 Subject: [PATCH] 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! --- modules/libcom/src/osi/os/vxWorks/osdTime.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/libcom/src/osi/os/vxWorks/osdTime.cpp b/modules/libcom/src/osi/os/vxWorks/osdTime.cpp index 49ccafc48..7275d8d16 100644 --- a/modules/libcom/src/osi/os/vxWorks/osdTime.cpp +++ b/modules/libcom/src/osi/os/vxWorks/osdTime.cpp @@ -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; }