[chrony-dev] [PATCH v2 4/6] leapdb: store data source in a function pointer |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH v2 4/6] leapdb: store data source in a function pointer
- From: patrick.oppenlander@xxxxxxxxx
- Date: Thu, 30 Nov 2023 14:23:27 +1100
- Cc: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701314622; x=1701919422; 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=tsCjUCr0gpvaKuT5uHvYmL9In7GPVhjSOD6EXgk+eQQ=; b=HN+aiXJnA5kA+2foA08sumFPr2AeQDAIJKmCfJZvOkKJaJxPHV7Vaw2EDXsGqOrx06 hgzgg7y7OPt8s5vXQFWSBELNQ0aJ+zts1PA2g/qEuGn1luCG8U3tzqHYRWLXGbDb4X2B A4K9pMyAWNM3rzN1Ae9TT0GfBGT2pcueMf+VBm8XIy55rcg8jxyvUS+XF4W3ZXj5Xgc7 Lt32BWuKJtF4+8XpnMwvZP6bxWmSk0kOS5zeRQtDPuM42+Z3d7XTY6TD888R70Oxemor agDg95SWFqxRYH9FrmnAvdVLuxJLeJkcng04+Porg1mmELfYDox/hAX+Tv8YkZ+JPVYk 8Zzg==
From: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
Instead of testing whether leap_tzname is set, use a function pointer to
store the leap second data source.
Doing this reduces the scope of changes required to add another leap
second source to LDB_Initialise().
---
leapdb.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/leapdb.c b/leapdb.c
index 17c9872..98bb2f5 100644
--- a/leapdb.c
+++ b/leapdb.c
@@ -35,8 +35,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;
+/* Current leap second data source */
+GetLeapFn get_leap;
/* ================================================== */
@@ -61,7 +61,7 @@ get_tz_leap(time_t when, int *tai_offset)
return tz_leap;
strcpy(tz_orig, tz_env);
}
- setenv("TZ", leap_tzname, 1);
+ setenv("TZ", CNF_GetLeapSecTimezone(), 1);
tzset();
/* Get the TAI-UTC offset, which started at the epoch at 10 seconds */
@@ -113,14 +113,16 @@ check_leap_source(GetLeapFn fn)
void
LDB_Initialise(void)
{
- leap_tzname = CNF_GetLeapSecTimezone();
+ const char *leap_tzname = CNF_GetLeapSecTimezone();
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)
+ if (leap_tzname) {
LOG(LOGS_INFO, "Using %s timezone to obtain leap second data", leap_tzname);
+ get_leap = get_tz_leap;
+ }
}
/* ================================================== */
@@ -141,8 +143,8 @@ LDB_GetLeap(time_t when, int *tai_offset)
db_leap = LEAP_Normal;
db_tai_offset = 0;
- if (leap_tzname)
- db_leap = get_tz_leap(when, &db_tai_offset);
+ if (get_leap)
+ db_leap = get_leap(when, &db_tai_offset);
out:
*tai_offset = db_tai_offset;
--
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.