]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: make driftfile update interval configurable
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 12 Nov 2024 15:01:03 +0000 (16:01 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Nov 2024 12:43:18 +0000 (13:43 +0100)
Add interval option to the driftfile directive to specify the minimum
interval between updates of the recorded frequency offset and skew.

conf.c
conf.h
doc/chrony.conf.adoc
reference.c
rtc.c

diff --git a/conf.c b/conf.c
index cbb113044cea6f11ce302cd6fb28579abfb9ba40..8d2074928c8be52917020ede3510787f8087b816 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -67,6 +67,7 @@ static void parse_bindcmdaddress(char *);
 static void parse_broadcast(char *);
 static void parse_clientloglimit(char *);
 static void parse_confdir(char *);
+static void parse_driftfile(char *);
 static void parse_fallbackdrift(char *);
 static void parse_hwtimestamp(char *);
 static void parse_include(char *);
@@ -98,6 +99,7 @@ static int acquisition_port = -1;
 static int ntp_port = NTP_PORT;
 static char *keys_file = NULL;
 static char *drift_file = NULL;
+static int drift_file_interval = 3600;
 static char *rtc_file = NULL;
 static double max_update_skew = 1000.0;
 static double correction_time_ratio = 3.0;
@@ -614,7 +616,7 @@ CNF_ParseLine(const char *filename, int number, char *line)
   } else if (!strcasecmp(command, "deny")) {
     parse_allow_deny(p, ntp_restrictions, 0);
   } else if (!strcasecmp(command, "driftfile")) {
-    parse_string(p, &drift_file);
+    parse_driftfile(p);
   } else if (!strcasecmp(command, "dscp")) {
     parse_int(p, &ntp_dscp);
   } else if (!strcasecmp(command, "dumpdir")) {
@@ -1655,6 +1657,29 @@ parse_confdir(char *line)
 
 /* ================================================== */
 
+static void
+parse_driftfile(char *line)
+{
+  char *path, *opt, *val;
+
+  path = line;
+  opt = CPS_SplitWord(path);
+  val = CPS_SplitWord(opt);
+
+  if (*path == '\0' ||
+      (*opt != '\0' && (strcasecmp(opt, "interval") != 0 ||
+                        sscanf(val, "%d", &drift_file_interval) != 1 ||
+                        *CPS_SplitWord(val) != '\0'))) {
+    command_parse_error();
+    return;
+  }
+
+  Free(drift_file);
+  drift_file = Strdup(path);
+}
+
+/* ================================================== */
+
 static void
 parse_include(char *line)
 {
@@ -1980,8 +2005,9 @@ CNF_GetAcquisitionPort(void)
 /* ================================================== */
 
 char *
-CNF_GetDriftFile(void)
+CNF_GetDriftFile(int *interval)
 {
+  *interval = drift_file_interval;
   return drift_file;
 }
 
diff --git a/conf.h b/conf.h
index 8136275d0528d80e04cdad41586e6ab66a220a11..e471f25fca33171b68cc46a4bd68ccc8b4080234 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -56,7 +56,7 @@ extern void CNF_ReloadSources(void);
 
 extern int CNF_GetAcquisitionPort(void);
 extern int CNF_GetNTPPort(void);
-extern char *CNF_GetDriftFile(void);
+extern char *CNF_GetDriftFile(int *interval);
 extern char *CNF_GetLogDir(void);
 extern char *CNF_GetDumpDir(void);
 extern int CNF_GetLogBanner(void);
index 9879b44c8cbe8ba6d0f5b45c02c11ca27778b99b..42c65cbdcf74a5c86c54079c4caeb132a04d87f5 100644 (file)
@@ -1136,7 +1136,7 @@ The maximum allowed slew rate can be set by the <<maxslewrate,*maxslewrate*>>
 directive. The current remaining correction is shown in the
 <<chronyc.adoc#tracking,*tracking*>> report as the *System time* value.
 
-[[driftfile]]*driftfile* _file_::
+[[driftfile]]*driftfile* _file_ [*interval* _interval_]::
 One of the main activities of the *chronyd* program is to work out the rate at
 which the system clock gains or loses time relative to real time.
 +
@@ -1155,6 +1155,10 @@ microseconds in reality (so the true time has only advanced by 999900
 microseconds). The second is an estimate of the error bound around the first
 value in which the true rate actually lies.
 +
+The *interval* option specifies the minimum interval between updates of the
+file in seconds. The file is written only on an update of the local clock.
+The default interval is 3600 seconds.
++
 An example of the driftfile directive is:
 +
 ----
index bb2c48a06a759e9c6a2c239026e6d1a7359bbe3d..efce3679311901459704c2ec86c1418faeb06fc7 100644 (file)
@@ -47,9 +47,6 @@
 /* The update interval of the reference in the local reference mode */
 #define LOCAL_REF_UPDATE_INTERVAL 64.0
 
-/* Interval between updates of the drift file */
-#define MAX_DRIFTFILE_AGE 3600.0
-
 static int are_we_synchronised;
 static int enable_local_stratum;
 static int local_stratum;
@@ -110,6 +107,7 @@ static REF_ModeEndHandler mode_end_handler = NULL;
 /* Filename of the drift file. */
 static char *drift_file=NULL;
 static double drift_file_age;
+static int drift_file_interval;
 
 static void update_drift_file(double, double);
 
@@ -213,7 +211,7 @@ REF_Initialise(void)
   local_activate_ok = 0;
 
   /* Now see if we can get the drift file opened */
-  drift_file = CNF_GetDriftFile();
+  drift_file = CNF_GetDriftFile(&drift_file_interval);
   if (drift_file) {
     in = UTI_OpenFile(NULL, drift_file, NULL, 'r', 0);
     if (in) {
@@ -1005,7 +1003,7 @@ REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
   if (drift_file) {
     /* Update drift file at most once per hour */
     drift_file_age += update_interval;
-    if (drift_file_age >= MAX_DRIFTFILE_AGE) {
+    if (drift_file_age >= drift_file_interval) {
       update_drift_file(local_abs_frequency, our_skew);
       drift_file_age = 0.0;
     }
diff --git a/rtc.c b/rtc.c
index d9465416088b24b21adb0a5e858099437a761052..4e9cabbe845e6703e0668c476d9a0ff11300711a 100644 (file)
--- a/rtc.c
+++ b/rtc.c
@@ -81,8 +81,9 @@ get_driftfile_time(void)
 {
   struct stat buf;
   char *drift_file;
+  int interval;
 
-  drift_file = CNF_GetDriftFile();
+  drift_file = CNF_GetDriftFile(&interval);
   if (!drift_file)
     return 0;