[chrony-dev] [PATCH v2 3/6] leapdb: move source check into separate function |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH v2 3/6] leapdb: move source check into separate function
- From: patrick.oppenlander@xxxxxxxxx
- Date: Thu, 30 Nov 2023 14:23:26 +1100
- Cc: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701314620; x=1701919420; 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=pmCJV4dvrRAJThY4abxRcCCKNHBOzBtYfuA4kQI1iBM=; b=N7Z0YCJvQTht59Pap0ttme0n06eCYq56RVxDPXLppSQyZjGHAl21/kB1ZS2yQY16cG 8XCdB+4CJZdYYWH5wShXOogw4zHFnPYlxV4nLMZdx0fEiVNL9uQUhvKVdS8V2LsCmn2M DU0veMUVM88J/UbrLd/1Ci/VbnDEqSnj+Fs02JFdSvL7kWQ6IzRAJRGXgHmAJLvq8LW7 8QO+869NLGVsqookqJuXdJRFtdxS0ZSIL3kz734t7NpqPnp/L9gceUTo9rN7fyybt7CE DdXqP9d2aPF+RC3vrYtrLOW++0YZ68tGDuJ3GXvxj9UHkbJKzuOE5ku1e0FTy3m7BjuZ yGOw==
From: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
The sanity checks are valid for all possible sources of leap second
information, so move them into a separate function check_leap_source().
---
leapdb.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/leapdb.c b/leapdb.c
index 91dbf9e..17c9872 100644
--- a/leapdb.c
+++ b/leapdb.c
@@ -33,6 +33,8 @@
/* ================================================== */
+typedef NTP_Leap (*GetLeapFn)(time_t when, int *tai_offset);
+
/* Name of a system timezone containing leap seconds occuring at midnight */
static char *leap_tzname;
@@ -93,22 +95,32 @@ get_tz_leap(time_t when, int *tai_offset)
/* ================================================== */
-void
-LDB_Initialise(void)
+static int
+check_leap_source(GetLeapFn fn)
{
int tai_offset;
+ /* Check that the leap second source has good data for Jun 30 2012 and Dec 31 2012 */
+ if (fn(1341014400, &tai_offset) == LEAP_InsertSecond && tai_offset == 34 &&
+ fn(1356912000, &tai_offset) == LEAP_Normal && tai_offset == 35)
+ return 1;
+
+ return 0;
+}
+
+/* ================================================== */
+
+void
+LDB_Initialise(void)
+{
leap_tzname = CNF_GetLeapSecTimezone();
- if (leap_tzname) {
- /* Check that the timezone has good data for Jun 30 2012 and Dec 31 2012 */
- if (get_tz_leap(1341014400, &tai_offset) == LEAP_InsertSecond && tai_offset == 34 &&
- get_tz_leap(1356912000, &tai_offset) == LEAP_Normal && tai_offset == 35) {
- LOG(LOGS_INFO, "Using %s timezone to obtain leap second data", leap_tzname);
- } else {
- LOG(LOGS_WARN, "Timezone %s failed leap second check, ignoring", leap_tzname);
- leap_tzname = NULL;
- }
+ if (leap_tzname && !check_leap_source(get_tz_leap)) {
+ LOG(LOGS_WARN, "Timezone %s failed leap second check, ignoring", leap_tzname);
+ leap_tzname = NULL;
}
+
+ if (leap_tzname)
+ LOG(LOGS_INFO, "Using %s timezone to obtain leap second data", leap_tzname);
}
/* ================================================== */
--
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.