From: Patrick Oppenlander
The existing implementation of getting leap second information from a
timezone in get_tz_leap() relies on non-portable C library behaviour.
This leads to "Timezone right/UTC failed leap second check, ignoring"
errors on musl based systems as musl does not support right/* timezones
or returning leap second information in the tm_sec field of struct tm.
This patch adds support for getting leap second information from the
leap-seconds.list file included with tzdata and adds a new configuration
directive leapsecdb to switch on the feature.
---
conf.c | 14
conf.h | 1 +
doc/chrony.conf.adoc | 19 -
reference.c | 162 +--
4 files changed, 188 insertions(+), 8 deletions(-)
diff --git a/conf.c b/conf.c
index fa74459..3b1f70c 100644
--- a/conf.c
+++ b/conf.c
@@ -249,6 +249,9 @@ static REF_LeapMode leapsec_mode = REF_LeapModeSystem;
/* Name of a system timezone containing leap seconds occuring at midnight */
static char *leapsec_tz = NULL;
+/* File name of leap second database, usually
/usr/share/zoneinfo/leap-seconds.list */
+static char *leapsec_db = NULL;
+
/* Name of the user to which will be dropped root privileges. */
static char *user;
@@ -471,6 +474,7 @@ CNF_Finalise(void)
Free(hwclock_file);
Free(keys_file);
Free(leapsec_tz);
+ Free(leapsec_db);
Free(logdir);
Free(bind_ntp_iface);
Free(bind_acq_iface);
@@ -620,6 +624,8 @@ CNF_ParseLine(const char *filename, int number, char *line)
parse_leapsecmode(p);
} else if (!strcasecmp(command, "leapsectz")) {
parse_string(p, _tz);
+ } else if (!strcasecmp(command, "leapsecdb")) {
+parse_string(p, _db);
} else if (!strcasecmp(command, "local")) {
parse_local(p);
} else if (!strcasecmp(command, "lock_all")) {
@@ -2386,6 +2392,14 @@ CNF_GetLeapSecTimezone(void)
/* == */
+char *
+CNF_GetLeapSecDatabase(void)
+{
+ return leapsec_db;
+}
+
+/* == */
+
int
CNF_GetSchedPriority(void)
{
diff --git a/conf.h b/conf.h
index 58ebdeb..b6d9827 100644
--- a/conf.h
+++ b/conf.h
@@ -91,6 +91,7 @@ extern char *CNF_GetNtpSigndSocket(void);
extern char *CNF_GetPidFile(void);
extern REF_LeapMode CNF_GetLeapSecMode(void);
extern char *CNF_GetLeapSecTimezone(void);
+extern char *CNF_GetLeapSecDatabase(void);
/* Value returned in ppm, as read from file */
extern double CNF_GetMaxUpdateSkew(void);
diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc
index abb8403..2c223fb 100644
--- a/doc/chrony.conf.adoc
+++ b/doc/chrony.conf.adoc
@@ -672,9 +672,10 @@ trusted and required source.
*tai*:::
This option indicates that the reference clock keeps time in TAI instead of UTC
and that *chronyd* should correct its offset by the current TAI-UTC offset. The
-<> directive must be used with this option and the
-database must be kept up to date in order for this correction to work as
-expected. This option does not make sense with PPS refclocks.
+<> or <> directive must be used
+with this option and the database must be kept up to date in order for this
+correction to work as expected. This option does not make sense with PPS
+refclocks.
*local*:::
This option specifies that the reference clock is an unsynchronised clock which
is more stable than the system clock (e.g. TCXO, OCXO, or atomic clock) and
@@ -1261,6 +1262,18 @@ $ TZ=right/UTC date -d 'Dec 31 2008 23:59:60'
Wed Dec 31 23:59:60 UTC 2008
+[[leapsecdb]]*leapsecdb* _file_::
+This directive specifies the path to a file containing a list of leap seconds.
+It is recommended to use the file _leap-seconds.list_ usually included with the
+system timezone database. The behaviour of this directive is otherwise
equivalent
+to <>.
++
+An example of this directive is:
++
+
+leapsecdb /usr/share/zoneinfo/leap-seconds.list
+
+
[[makestep]]*makestep* _threshold_ _limit_::
Normally *chronyd* will cause the system to gradually correct any time offset,
by slowing down or speeding up the clock as required. In certain situations,
diff --git a/reference.c b/reference.c
index 97dfbe9..9d365eb 100644
--- a/reference.c
+++ b/reference.c
@@ -125,6 +125,9 @@ static SCH_TimeoutID leap_timeout_id;
/* Name of a system timezone containing leap seconds occuring at midnight */
static char *leap_tzname;
+/* File name of leap second database, usually
/usr/share/zoneinfo/leap-seconds.list */
+static char *leap_db;
+
/* == */
static LOG_FileID logfileid;
@@ -155,7 +158,20 @@ static int ref_adjustments;
/* == */
+/* Leap second database */
+struct leapdb {
+ long long updated;
+ long long expiry;
+ size_t len;
+ struct leap {
+long long when;
+int tai_offset;
+ } leap[];
+};
+
static NTP_Leap get_tz_leap(time_t when, int *tai_offset);
+static