Browse Source

add adjtimex over adjtime for supported OSes

OPENBSD_6_5
Brent Cook 5 years ago
parent
commit
c551d18d1f
14 changed files with 87 additions and 13 deletions
  1. +1
    -1
      patches/0001-Handle-IPv6-DNS-records-on-IPv4-networks-more-libera.patch
  2. +1
    -1
      patches/0002-EAI_NODATA-does-not-exist-everywhere.patch
  3. +1
    -1
      patches/0003-conditionally-fill-in-sin_len-sin6_len-if-they-exist.patch
  4. +1
    -1
      patches/0004-check-if-rdomain-support-is-available.patch
  5. +1
    -1
      patches/0005-update-ntpd.conf-to-indicate-OS-dependent-options.patch
  6. +1
    -1
      patches/0006-allow-overriding-default-user-and-file-locations.patch
  7. +1
    -1
      patches/0007-add-p-option-to-create-a-pid-file.patch
  8. +1
    -1
      patches/0008-initialize-setproctitle-where-needed.patch
  9. +1
    -1
      patches/0009-Notify-the-user-when-constraint-support-is-disabled.patch
  10. +1
    -1
      patches/0010-add-a-method-for-updating-the-realtime-clock-on-sync.patch
  11. +1
    -1
      patches/0011-Deal-with-missing-SO_TIMESTAMP.patch
  12. +1
    -1
      patches/0012-check-result-of-ftello-ftruncate.patch
  13. +1
    -1
      patches/0013-set-IPV6_V6ONLY-if-we-are-binding-to-an-IPv6-address.patch
  14. +74
    -0
      patches/0014-use-adjtimex-over-adjtime-check-return-value-and-adj.patch

+ 1
- 1
patches/0001-Handle-IPv6-DNS-records-on-IPv4-networks-more-libera.patch View File

@ -1,7 +1,7 @@
From 641fc1e7220515456c33a8991890a91608a5b983 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:10:22 -0600
Subject: [PATCH 01/13] Handle IPv6 DNS records on IPv4 networks more liberally
Subject: [PATCH 01/14] Handle IPv6 DNS records on IPv4 networks more liberally
Rather than fail on IPv4 only networks when seeing an IPv6 DNS record,
just give a warning.


+ 1
- 1
patches/0002-EAI_NODATA-does-not-exist-everywhere.patch View File

@ -1,7 +1,7 @@
From 683cb25dcb78b92c29c5148becece3cf4f0c6a28 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:04:08 -0600
Subject: [PATCH 02/13] EAI_NODATA does not exist everywhere
Subject: [PATCH 02/14] EAI_NODATA does not exist everywhere
FreeBSD says it is deprecated #ifdef's it out.


+ 1
- 1
patches/0003-conditionally-fill-in-sin_len-sin6_len-if-they-exist.patch View File

@ -1,7 +1,7 @@
From 5d2c25bfd0ff11d74ac912313d405247cbaf5ee2 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:02:50 -0600
Subject: [PATCH 03/13] conditionally fill in sin_len/sin6_len if they exist
Subject: [PATCH 03/14] conditionally fill in sin_len/sin6_len if they exist
---
src/usr.sbin/ntpd/parse.y | 8 +++++---


+ 1
- 1
patches/0004-check-if-rdomain-support-is-available.patch View File

@ -1,7 +1,7 @@
From 546b4b7926dc14f0ea6a60182af23b865e0d18ad Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:05:46 -0600
Subject: [PATCH 04/13] check if rdomain support is available.
Subject: [PATCH 04/14] check if rdomain support is available.
Handle FreeBSD's calling rdomain 'FIB'.
- from naddy@openbsd.org


+ 1
- 1
patches/0005-update-ntpd.conf-to-indicate-OS-dependent-options.patch View File

@ -1,7 +1,7 @@
From 9395697554026abb8eb35dd6b268acb536b57d1d Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Tue, 30 Dec 2014 09:20:03 -0600
Subject: [PATCH 05/13] update ntpd.conf to indicate OS-dependent options
Subject: [PATCH 05/14] update ntpd.conf to indicate OS-dependent options
Also, clarify listening behavior based on a patch from
Dererk <dererk@debian.org>


+ 1
- 1
patches/0006-allow-overriding-default-user-and-file-locations.patch View File

@ -1,7 +1,7 @@
From 00ee3b5aea27bc10b3ad6b732dd582b65c74c795 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Thu, 1 Jan 2015 07:18:11 -0600
Subject: [PATCH 06/13] allow overriding default user and file locations
Subject: [PATCH 06/14] allow overriding default user and file locations
Allow the build process to override the default ntpd file paths and
default user.


+ 1
- 1
patches/0007-add-p-option-to-create-a-pid-file.patch View File

@ -1,7 +1,7 @@
From a9008bf22c4f706cf2a4ce12dac9eb282f295933 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Wed, 31 Dec 2014 08:26:41 -0600
Subject: [PATCH 07/13] add -p option to create a pid file
Subject: [PATCH 07/14] add -p option to create a pid file
This is used in both the Gentoo and Debian ports.


+ 1
- 1
patches/0008-initialize-setproctitle-where-needed.patch View File

@ -1,7 +1,7 @@
From fb2c22a2d06541415f153e195ce577e475cdf26a Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Mon, 12 Jan 2015 06:18:31 -0600
Subject: [PATCH 08/13] initialize setproctitle where needed
Subject: [PATCH 08/14] initialize setproctitle where needed
We need to save a copy of argv and __progname to avoid setproctitle
clobbering them.


+ 1
- 1
patches/0009-Notify-the-user-when-constraint-support-is-disabled.patch View File

@ -1,7 +1,7 @@
From 1c8dc7b9bda86123ccc6744142a80520b75e0b9e Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Fri, 27 Mar 2015 23:14:15 -0500
Subject: [PATCH 09/13] Notify the user when constraint support is disabled.
Subject: [PATCH 09/14] Notify the user when constraint support is disabled.
Update the manpage and warn if constraints are
configured but ntpd is built without libtls present.


+ 1
- 1
patches/0010-add-a-method-for-updating-the-realtime-clock-on-sync.patch View File

@ -1,7 +1,7 @@
From 6f16675197729ad7cbcb03fa2f95b38a08e92679 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Mon, 4 May 2015 04:27:29 -0500
Subject: [PATCH 10/13] add a method for updating the realtime clock on sync
Subject: [PATCH 10/14] add a method for updating the realtime clock on sync
from Christian Weisgerber
---


+ 1
- 1
patches/0011-Deal-with-missing-SO_TIMESTAMP.patch View File

@ -1,7 +1,7 @@
From b6d55ddfe09268467fa7953037be7383bbab7154 Mon Sep 17 00:00:00 2001
From: Brent Cook <bcook@openbsd.org>
Date: Sun, 6 Dec 2015 22:35:38 -0600
Subject: [PATCH 11/13] Deal with missing SO_TIMESTAMP
Subject: [PATCH 11/14] Deal with missing SO_TIMESTAMP
from Paul B. Henson" <henson@acm.org>


+ 1
- 1
patches/0012-check-result-of-ftello-ftruncate.patch View File

@ -1,7 +1,7 @@
From b8220a87e4121bd764aa6bf092bd2a2a323c883c Mon Sep 17 00:00:00 2001
From: Brent Cook <bcook@openbsd.org>
Date: Mon, 21 Dec 2015 05:53:20 -0600
Subject: [PATCH 12/13] check result of ftello/ftruncate
Subject: [PATCH 12/14] check result of ftello/ftruncate
---
src/usr.sbin/ntpd/ntpd.c | 7 +++++--


+ 1
- 1
patches/0013-set-IPV6_V6ONLY-if-we-are-binding-to-an-IPv6-address.patch View File

@ -1,7 +1,7 @@
From 4f01d08765ee2d031e703e3201a07793247fa323 Mon Sep 17 00:00:00 2001
From: Brent Cook <bcook@openbsd.org>
Date: Sat, 13 Aug 2016 14:22:02 -0500
Subject: [PATCH 13/13] set IPV6_V6ONLY if we are binding to an IPv6 address
Subject: [PATCH 13/14] set IPV6_V6ONLY if we are binding to an IPv6 address
---
src/usr.sbin/ntpd/server.c | 9 +++++++++


+ 74
- 0
patches/0014-use-adjtimex-over-adjtime-check-return-value-and-adj.patch View File

@ -0,0 +1,74 @@
From 98f4a4523f158129a49b16a4e0ccc4bb50a62a31 Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Sat, 19 Jan 2019 04:25:44 -0600
Subject: [PATCH 14/14] use adjtimex over adjtime, check return value and
adjust offset as needed
---
src/usr.sbin/ntpd/ntpd.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
index c3b7ab07e1..4d840767b0 100644
--- a/src/usr.sbin/ntpd/ntpd.c
+++ b/src/usr.sbin/ntpd/ntpd.c
@@ -17,6 +17,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_ADJTIMEX
+#include <sys/timex.h>
+#endif
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/socket.h>
@@ -478,21 +481,43 @@ reset_adjtime(void)
int
ntpd_adjtime(double d)
{
- struct timeval tv, olddelta;
int synced = 0;
static int firstadj = 1;
+ double threshold = (double)LOG_NEGLIGIBLE_ADJTIME / 1000;
d += getoffset();
- if (d >= (double)LOG_NEGLIGIBLE_ADJTIME / 1000 ||
- d <= -1 * (double)LOG_NEGLIGIBLE_ADJTIME / 1000)
+ if (d >= threshold || d <= -1 * threshold)
log_info("adjusting local clock by %fs", d);
else
log_debug("adjusting local clock by %fs", d);
+
+#ifdef HAVE_ADJTIMEX
+ int rc;
+
+ long offset = d * 1000000;
+ struct timex tx = { 0 };
+ tx.offset = offset;
+ tx.modes = ADJ_OFFSET_SINGLESHOT;
+
+ do {
+ rc = adjtimex(&tx);
+ } while (rc == TIME_ERROR && (tx.offset /= 2) > threshold);
+
+ if (rc == TIME_ERROR) {
+ log_warn("adjtimex returned TIME_ERROR");
+ } else if (rc < 0) {
+ log_warn("adjtimex failed");
+ } else if (tx.offset == offset) {
+ synced = 1;
+ }
+#else
+ struct timeval tv, olddelta;
d_to_tv(d, &tv);
if (adjtime(&tv, &olddelta) == -1)
log_warn("adjtime failed");
else if (!firstadj && olddelta.tv_sec == 0 && olddelta.tv_usec == 0)
synced = 1;
+#endif
firstadj = 0;
update_time_sync_status(synced);
return (synced);
--
2.20.1

Loading…
Cancel
Save