[chrony-dev] [PATCH v2 2/6] leapdb: make twice per day check logic common |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH v2 2/6] leapdb: make twice per day check logic common
- From: patrick.oppenlander@xxxxxxxxx
- Date: Thu, 30 Nov 2023 14:23:25 +1100
- Cc: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701314618; x=1701919418; darn=chrony.tuxfamily.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S7IUImQyJVy7dmQA4KniRsNR1IZZz71w80qxslMj1GA=; b=hdsERNyyaMK7hRq/KDEU9PDhOWBX8Im4MEYbNz2S4XtiWUEC55OIySVuzPJjAl/x6p m+CDi/mLi72oakXNb1TvLD+Op+zJoUD0nEB/96jNs2/wBb/fPI1I0nZ0BEs7i2kZ6wlT hDZdjQysJpZ15rRT8nLibae+/bGoufRyPsdnxuU9/vbrFaR9UvmG1RRexl8PJm5m+HaA GdCoemPwy/TDO6u+d/P3wNWKCBgiVO3CYLClnFfej5G/Jy89fMRXBauALq2ifsygB1oV /IlrCv+GDydBhmXuXf7nL8ZSVhs14oZxS1eaU5ugKj3orkPaN0jjeU3ibDFY3u/C5Isk VA5w==
From: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
We want to do the twice per day check regardless of the data source.
Move the check up one level from get_tz_leap() into LDB_GetLeap().
---
leapdb.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/leapdb.c b/leapdb.c
index d184390..91dbf9e 100644
--- a/leapdb.c
+++ b/leapdb.c
@@ -41,24 +41,10 @@ static char *leap_tzname;
static NTP_Leap
get_tz_leap(time_t when, int *tai_offset)
{
- static time_t last_tz_leap_check;
- static NTP_Leap tz_leap;
- static int tz_tai_offset;
-
struct tm stm, *tm;
time_t t;
char *tz_env, tz_orig[128];
-
- *tai_offset = tz_tai_offset;
-
- /* Do this check at most twice a day */
- when = when / (12 * 3600) * (12 * 3600);
- if (last_tz_leap_check == when)
- return tz_leap;
-
- last_tz_leap_check = when;
- tz_leap = LEAP_Normal;
- tz_tai_offset = 0;
+ NTP_Leap tz_leap = LEAP_Normal;
tm = gmtime(&when);
if (!tm)
@@ -79,7 +65,7 @@ get_tz_leap(time_t when, int *tai_offset)
/* Get the TAI-UTC offset, which started at the epoch at 10 seconds */
t = mktime(&stm);
if (t != -1)
- tz_tai_offset = t - when + 10;
+ *tai_offset = t - when + 10;
/* Set the time to 23:59:60 and see how it overflows in mktime() */
stm.tm_sec = 60;
@@ -102,8 +88,6 @@ get_tz_leap(time_t when, int *tai_offset)
else if (stm.tm_sec == 1)
tz_leap = LEAP_DeleteSecond;
- *tai_offset = tz_tai_offset;
-
return tz_leap;
}
@@ -132,10 +116,25 @@ LDB_Initialise(void)
NTP_Leap
LDB_GetLeap(time_t when, int *tai_offset)
{
- *tai_offset = 0;
+ static time_t last_db_leap_check;
+ static NTP_Leap db_leap;
+ static int db_tai_offset;
+
+ /* Do this check at most twice a day */
+ when = when / (12 * 3600) * (12 * 3600);
+ if (last_db_leap_check == when)
+ goto out;
+
+ last_db_leap_check = when;
+ db_leap = LEAP_Normal;
+ db_tai_offset = 0;
+
if (leap_tzname)
- return get_tz_leap(when, tai_offset);
- return LEAP_Normal;
+ db_leap = get_tz_leap(when, &db_tai_offset);
+
+out:
+ *tai_offset = db_tai_offset;
+ return db_leap;
}
/* ================================================== */
--
2.43.0
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.