diff --git a/README.md b/README.md index 46ae538..a0568ee 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,20 @@ See also [my blog post on fjordtek.com](https://fjordtek.com/categories/news/202 ## Files -| File | Description | -|----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------| -| [1-patch_better-logs.patch](patches/1-patch_better-logs.patch) | Provide human-readable error messages for easier process interpretation | -| [2-patch_ntpctl-sensors-tolowercase.patch](patches/2-patch_ntpctl-sensors-tolowercase.patch) | Set 'Sensors' to lowercase in `ntpctl` settings | -| [3-patch_unhardcode-ports.patch](patches/3-patch_unhardcode-ports.patch) | Unhardcode NTP server, client and constraint UDP & TCP port numbers | -| [4-patch_peercount-init.patch](patches/4-patch_peercount-init.patch) | Fix C compiler warning about uninitialized variable peercount | -| [5-patch_debugmode-fix.patch](patches/5-patch_debugmode-fix.patch) | Fix debug mode not showing output in command line | -| [6-patch_unhardcode-conf.patch](patches/6-patch_unhardcode-conf.patch) | Unhardcode majority of configuration settings, update manual | -| [7-patch_implement-openssl.patch](patches/7-patch_implement-openssl.patch) | Implement OpenSSL support, update manual, update ChangeLog | -| [8-patch_update-conf.patch](patches/8-patch_update-conf.patch) | Update default configuration file | -| [9-patch_add-constraint-useragent.patch](patches/9-patch_add-constraint-useragent.patch) | Add user agent string support for HTTPS constraints, update ChangeLog | -| [10-patch_peer-constraint-logs.patch](patches/10-patch_peer-constraint-logs.patch) | Improve constraint & NTP peer log entries; update conf & man | -| [11-patch_fix-constraint-time-overflow-32bit.patch](patches/11-patch_fix-constraint-time-overflow-32bit.patch) | Cast constraint median time value to unsigned long. Fixes overflow on 32-bit systems. | +| File | Description | +|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| +| [1-patch_better-logs.patch](patches/1-patch_better-logs.patch) | Provide human-readable error messages for easier process interpretation | +| [2-patch_ntpctl-sensors-tolowercase.patch](patches/2-patch_ntpctl-sensors-tolowercase.patch) | Set 'Sensors' to lowercase in `ntpctl` settings | +| [3-patch_unhardcode-ports.patch](patches/3-patch_unhardcode-ports.patch) | Unhardcode NTP server, client and constraint UDP & TCP port numbers | +| [4-patch_peercount-init.patch](patches/4-patch_peercount-init.patch) | Fix C compiler warning about uninitialized variable peercount | +| [5-patch_debugmode-fix.patch](patches/5-patch_debugmode-fix.patch) | Fix debug mode not showing output in command line | +| [6-patch_unhardcode-conf.patch](patches/6-patch_unhardcode-conf.patch) | Unhardcode majority of configuration settings, update manual | +| [7-patch_implement-openssl.patch](patches/7-patch_implement-openssl.patch) | Implement OpenSSL support, update manual, update ChangeLog | +| [8-patch_update-conf.patch](patches/8-patch_update-conf.patch) | Update default configuration file | +| [9-patch_add-constraint-useragent.patch](patches/9-patch_add-constraint-useragent.patch) | Add user agent string support for HTTPS constraints, update ChangeLog | +| [10-patch_peer-constraint-logs.patch](patches/10-patch_peer-constraint-logs.patch) | Improve constraint & NTP peer log entries; update conf & man | +| [11-patch_fix-constraint-time-overflow-32bit.patch](patches/11-patch_fix-constraint-time-overflow-32bit.patch) | Cast constraint median time value to unsigned long. Fixes overflow on 32-bit systems. | +| [12-patch_fix-adjtime.patch](patches/12-patch_fix-adjtime.patch) | Assume system clock is synced when time offset is in specific range limits (quick hotfix). | ## Usage diff --git a/arch/openntpd-git/PKGBUILD b/arch/openntpd-git/PKGBUILD index 86ec67c..710e25b 100644 --- a/arch/openntpd-git/PKGBUILD +++ b/arch/openntpd-git/PKGBUILD @@ -44,6 +44,7 @@ patches=( 9-patch_add-constraint-useragent.patch 10-patch_peer-constraint-logs.patch 11-patch_fix-constraint-time-overflow-32bit.patch + 12-patch_fix-adjtime.patch ) source=(${source[@]} ${patches[@]}) @@ -61,7 +62,8 @@ sha512sums=('SKIP' 'e162c1bd321d68a3a42fca82d2b0ad0c6031293d4d47d4bc69bbaa9825774c4a02b6f7c0ecc3688f8029b93df08af24c34128cc4bc15eccd6ddd344a94877056' '26a2aadc40472d854b8ad1c454c5689c0703ace7836498dbf3f52664610820e2747e22307929446354a973b79dea236c73196ab30deeaa8ffdfde4286e10d3c9' '3ae3501a41ee50519b19074bf9e532718e365e6b45a9af4a9fba81d4276df98244cd5aac7acc9f6cd7d7a2bf460b4714e79e2676f826859fe4ad43b67046c709' - '62f99efe913598fad09e6d9ca418813beeff01c4cd22861296f998b3ef87bf0b2b5c7fd018976929b4a0d8f485b2afa4a0c62c00aeb2b738d08a944ef8fa0d19') + '62f99efe913598fad09e6d9ca418813beeff01c4cd22861296f998b3ef87bf0b2b5c7fd018976929b4a0d8f485b2afa4a0c62c00aeb2b738d08a944ef8fa0d19' + '08c6ee834d98d9897eb00023364f285fc0515b33a04c1593595a9d3a96a894f2be08a5665ac72fee65e1dab66e4c4b43f7414abd1ef97f483e7e2dcba948c49a') validpgpkeys=('A1EB079B8D3EB92B4EBD3139663AF51BD5E4D8D5') # Brent Cook pkgver() { diff --git a/patches/12-patch_fix-adjtime.patch b/patches/12-patch_fix-adjtime.patch new file mode 100644 index 0000000..6993282 --- /dev/null +++ b/patches/12-patch_fix-adjtime.patch @@ -0,0 +1,121 @@ +From: Pekka Helenius +Date: Wed, 20 Jan 2021 23:20:31 +0300 +Subject: Assume system clock is synced when time offset is in specific range limits (quick hotfix). + + +--- a/src/ntpd.c 2020-08-03 23:48:23.609231373 +0300 ++++ b/src/ntpd.c 2021-01-20 23:00:53.946365898 +0200 +@@ -566,9 +566,12 @@ ntpd_adjtime(double d) + log_warn("main process: time adjustment failed due to time error"); + } else if (rc < 0) { + log_warn("main process: time adjustment failed"); +- } else if (!firstadj && tx.offset == offset) { ++ } ++ if (tx.offset > -(conf->synced_offset) || tx.offset < conf->synced_offset) { + synced = 1; +- } ++ } else { ++ synced = 0; ++ } + #else + struct timeval tv, olddelta; + d_to_tv(d, &tv); +--- a/src/ntpd.h 2020-08-03 23:25:02.978705101 +0300 ++++ b/src/ntpd.h 2021-01-20 23:09:58.945735647 +0200 +@@ -76,6 +76,7 @@ + #define SETTIME_TIMEOUT 100 /* max seconds to wait when settime == 1 */ + #define LOG_NEGLIGIBLE_ADJTIME 32 /* negligible drift to not log (ms) */ + #define LOG_NEGLIGIBLE_ADJFREQ 0.05 /* negligible rate to not log (ppm) */ ++#define SYNCED_OFFSET 100 /* Synced time offset (μs) */ + #define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */ + #define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */ + #define MAX_SEND_ERRORS 3 /* max send errors before reconnect */ +@@ -313,6 +314,7 @@ struct ntpd_conf { + int settime_timeout; + + int log_negligible_adjtime; ++ int synced_offset; + double log_negligible_adjfreq; + + int frequency_samples; +--- a/src/parse.y 2020-08-03 23:22:43.401482642 +0300 ++++ b/src/parse.y 2021-01-20 23:08:20.789182596 +0200 +@@ -119,6 +119,8 @@ typedef struct { + %token _LOG_NEGLIGIBLE_ADJTIME + %token _LOG_NEGLIGIBLE_ADJFREQ + ++%token _SYNCED_OFFSET ++ + %token _FREQUENCY_SAMPLES + %token _MAX_FREQUENCY_ADJUST + +@@ -515,6 +517,10 @@ main : LISTEN ON address listen_opts { + conf->log_negligible_adjfreq = $2.pos_decimal; + } + ++ | _SYNCED_OFFSET pos_num { ++ conf->synced_offset = $2.pos_num; ++ } ++ + | _FREQUENCY_SAMPLES pos_num { + conf->frequency_samples = $2.pos_num; + } +@@ -918,6 +924,7 @@ lookup(char *s) + { "servers", SERVERS, "multiple" }, + { "settime_timeout", _SETTIME_TIMEOUT, "single" }, + { "stratum", STRATUM, "multiple" }, ++ { "synced_offset", _SYNCED_OFFSET, "single" }, + { "tries_auto_dnsfail", _TRIES_AUTO_DNSFAIL, "single" }, + { "trusted", TRUSTED, "multiple" }, + { "trustlevel_aggressive", _TRUSTLEVEL_AGGRESSIVE, "single" }, +@@ -1293,6 +1300,9 @@ init_conf(struct ntpd_conf *conf) + /* negligible rate to not log (ppm) */ + conf->log_negligible_adjfreq = LOG_NEGLIGIBLE_ADJFREQ; // 0.05; + ++ /* negligible drift to not log (ms) */ ++ conf->synced_offset = SYNCED_OFFSET; // 100; ++ + /* samples for est. of permanent drift */ + conf->frequency_samples = FREQUENCY_SAMPLES; // 8; + +@@ -1372,6 +1382,8 @@ print_conf(struct ntpd_conf *lconf) + fprintf(stdout, "Neglible drift time to not log: %d milliseconds\n", conf->log_negligible_adjtime); + fprintf(stdout, "Neglible frequency rate to not log: %f ppm\n", conf->log_negligible_adjfreq); + fprintf(stdout, "\n"); ++ fprintf(stdout, "Synced time offset threshold: %d microseconds\n", conf->synced_offset); ++ fprintf(stdout, "\n"); + fprintf(stdout, "Frequency samples for estimation of permanent drift: %d\n", conf->frequency_samples); + fprintf(stdout, "Maximum frequency correction per iteration: %f\n", conf->max_frequency_adjust); + fprintf(stdout, "\n"); +--- a/src/ntpd.conf.5 2020-08-03 23:21:11.124672226 +0300 ++++ b/src/ntpd.conf.5 2021-01-20 23:12:45.628871438 +0200 +@@ -676,6 +676,14 @@ Negligible drift time to not log in mill + 32 + .El + .Ed ++.It Ic synced_offset Ar microseconds ++Synced time offset threshold in microseconds. ++.Bd -literal -offset indent ++.Bl -tag -width "Default:" -compact ++.It Default: ++100 ++.El ++.Ed + .It Ic max_frequency_adjust Ar decimal + Maximum allowed frequency correction per iteration. + .Bd -literal -offset indent +--- a/ntpd.conf 2020-08-03 23:19:18.951338773 +0300 ++++ b/ntpd.conf 2021-01-20 23:14:56.802048541 +0200 +@@ -246,6 +246,12 @@ constraints from "https://www.duckduckgo + # + # log_negligible_adjtime 32 + ++# Synced time offset threshold in microseconds. ++# If our time adjustment value exceeds the threshold ++# we assume the clock is not synced anymore. ++# ++# synced_offset 100 ++ + # Maximum allowed frequency correction per iteration. + # + # max_frequency_adjust 0.0128