[chrony-dev] [PATCH 1/1] reference: support leap-seconds.list leap second source

2023-11-28 Thread patrick . oppenlander
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 

[chrony-dev] [PATCH 0/1] fix leap second source on musl based systems

2023-11-28 Thread patrick . oppenlander
From: Patrick Oppenlander 

Hi,

while testing chrony on an aarch64/musl system I noticed that the UTC-TAI
offset wasn't being set.

Turns out that chrony currently relies on some implementation defined C library
behaviour in get_tz_leap() leading to it rejecting the 'leapsectz right/UTC'
directive on musl based systems.

I think this is for two reasons:
1. musl doesn't support right/* timezones[1]
2. musl does not include leap second information (i.e. 60, or skip 59)
   in the tm_sec field of struct tm[2]

I've included a patch which adds support for reading leap-seconds.list and
using it as as another source of leap second information.

Patrick

[1] https://skarnet.org/lists/skaware/0089.html
[2] https://git.musl-libc.org/cgit/musl/tree/src/time/__secs_to_tm.c#n79

Patrick Oppenlander (1):
  reference: support leap-seconds.list as leap second source

 conf.c   |  14 
 conf.h   |   1 +
 doc/chrony.conf.adoc |  19 -
 reference.c  | 162 +--
 4 files changed, 188 insertions(+), 8 deletions(-)

-- 
2.43.0


-- 
To unsubscribe email chrony-dev-requ...@chrony.tuxfamily.org with "unsubscribe" 
in the subject.
For help email chrony-dev-requ...@chrony.tuxfamily.org with "help" in the 
subject.
Trouble?  Email listmas...@chrony.tuxfamily.org.



[chrony-dev] [Git][chrony/chrony][master] sources: rework logging of selection loss

2023-11-28 Thread Miroslav Lichvar (@mlichvar)


Miroslav Lichvar pushed to branch master at chrony / chrony


Commits:
3ee7b3e7 by Miroslav Lichvar at 2023-11-28T12:21:23+01:00
sources: rework logging of selection loss

The commit 5dd288dc0cbd (sources: reselect earlier when removing
selected source) didnt cover all paths that can lead to a missing log
message when all sources are removed.

Add a flag to track the loss of selection and postpone the log message
in transient states where no message is logged to avoid spamming in
normal operation. Call SRC_SelectSource() after removing the source
to get a log message if there are no (selectable) sources left.

Reported-by: Thomas Lange tho...@corelatus.se

- - - - -


1 changed file:

- sources.c


View it on GitLab: 
https://gitlab.com/chrony/chrony/-/commit/3ee7b3e786f4758e9799866b5a5a184b9a4e6bd3

-- 
View it on GitLab: 
https://gitlab.com/chrony/chrony/-/commit/3ee7b3e786f4758e9799866b5a5a184b9a4e6bd3
You're receiving this email because of your account on gitlab.com.