From: Patrick Oppenlander <[email protected]>
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 [email protected] with "unsubscribe"
in the subject.
For help email [email protected] with "help" in the
subject.
Trouble? Email [email protected].