From: Miroslav Lichvar Date: Tue, 12 Nov 2024 15:01:03 +0000 (+0100) Subject: reference: make driftfile update interval configurable X-Git-Tag: 4.7-pre1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9d97f76d7f8b359bad904d1ac3b85dc089e9512;p=thirdparty%2Fchrony.git reference: make driftfile update interval configurable Add interval option to the driftfile directive to specify the minimum interval between updates of the recorded frequency offset and skew. --- diff --git a/conf.c b/conf.c index cbb11304..8d207492 100644 --- 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 8136275d..e471f25f 100644 --- 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); diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 9879b44c..42c65cbd 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -1136,7 +1136,7 @@ The maximum allowed slew rate can be set by the <> directive. The current remaining correction is shown in the <> 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: + ---- diff --git a/reference.c b/reference.c index bb2c48a0..efce3679 100644 --- a/reference.c +++ b/reference.c @@ -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 d9465416..4e9cabbe 100644 --- 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;