]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
leapdb: move source check into separate function
authorPatrick Oppenlander <patrick.oppenlander@gmail.com>
Thu, 8 Feb 2024 03:36:27 +0000 (14:36 +1100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 8 Feb 2024 14:54:21 +0000 (15:54 +0100)
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

index 32f753aa5d19ba9e7b4a6b9ceef0afe30f747135..aa49b3c42406f18ad89789c160833489a4d74401 100644 (file)
--- a/leapdb.c
+++ b/leapdb.c
@@ -93,22 +93,32 @@ get_tz_leap(time_t when, int *tai_offset)
 
 /* ================================================== */
 
+static int
+check_leap_source(NTP_Leap (*src)(time_t when, int *tai_offset))
+{
+  int tai_offset = 0;
+
+  /* Check that the leap second source has good data for Jun 30 2012 and Dec 31 2012 */
+  if (src(1341014400, &tai_offset) == LEAP_InsertSecond && tai_offset == 34 &&
+      src(1356912000, &tai_offset) == LEAP_Normal && tai_offset == 35)
+    return 1;
+
+  return 0;
+}
+
+/* ================================================== */
+
 void
 LDB_Initialise(void)
 {
-  int tai_offset;
-
   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);
 }
 
 /* ================================================== */