[ntpsec commit] Fall back to a loca; implementation of ntp_gettime(2) if need be.

Eric S. Raymond esr at ntpsec.org
Wed Sep 30 20:13:13 UTC 2015


Module:    ntpsec
Branch:    master
Commit:    ce4034392acd35828ed9881c5d6f188180b168c0
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=ce4034392acd35828ed9881c5d6f188180b168c0

Author:    Eric S. Raymond <esr at thyrsus.com>
Date:      Wed Sep 30 16:07:38 2015 -0400

Fall back to a loca; implementation of ntp_gettime(2) if need be.

---

 include/ntp_syscall.h | 34 ++++++++--------------------------
 libntp/machines.c     | 21 +++++++++++++++++++++
 pylib/configure.py    |  2 ++
 3 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/include/ntp_syscall.h b/include/ntp_syscall.h
index b378aaa..a0d843e 100644
--- a/include/ntp_syscall.h
+++ b/include/ntp_syscall.h
@@ -1,6 +1,11 @@
 /*
  * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime()
  * 		   system calls.
+ *
+ * On most systems including <sys/timex.h> will bring in declarations
+ * for the BSD functions ntp_gettime(2) and ntp_adjtime(2). (Linux
+ * using glibc has these, though they're not visible in the manual
+ * pages.)
  */
 
 #ifndef GUARD_NTP_SYSCALL_H
@@ -11,9 +16,7 @@
 # include <sys/timex.h>
 #endif
 
-#ifdef HAVE_NTP_ADJTIME
-extern	int	ntp_adjtime	(struct timex *);
-
+#ifndef HAVE_NTP_GETTIME
 struct ntptimeval
 {
 	struct timeval	time;		/* current time (ro) */
@@ -21,28 +24,7 @@ struct ntptimeval
 	long int	esterror;	/* estimated error (us) (ro) */
 };
 
-# ifndef HAVE_NTP_GETTIME
-static inline int
-ntp_gettime(
-	struct ntptimeval *ntv
-	)
-{
-	struct timex tntx;
-	int result;
-
-	ZERO(tntx);
-	result = ntp_adjtime(&tntx);
-	ntv->time = tntx.time;
-	ntv->maxerror = tntx.maxerror;
-	ntv->esterror = tntx.esterror;
-#  ifdef NTP_API
-#   if NTP_API > 3
-	ntv->tai = tntx.tai;
-#   endif
-#  endif
-	return result;
-}
-# endif	/* !HAVE_NTP_GETTIME */
-#endif	/* !HAVE_NTP_ADJTIME */
+int ntp_gettime(struct ntptimeval *);
+#endif	/* !HAVE_NTP_GETTIME */
 
 #endif	/* GUARD_NTP_SYSCALL_H */
diff --git a/libntp/machines.c b/libntp/machines.c
index 0541d4f..18c2a6c 100644
--- a/libntp/machines.c
+++ b/libntp/machines.c
@@ -13,12 +13,33 @@
 #include "ntp_unixtime.h"
 #include "lib_strbuf.h"
 #include "ntp_debug.h"
+#include "ntp_syscall.h"
 #include <unistd.h>
 
 #ifdef SYS_WINNT
 int _getch(void);	/* Declare the one function rather than include conio.h */
 #else
 
+#ifndef HAVE_NTP_GETTIME
+int ntp_gettime(struct ntptimeval *ntv)
+{
+	struct timex tntx;
+	int result;
+
+	ZERO(tntx);
+	result = ntp_adjtime(&tntx);
+	ntv->time = tntx.time;
+	ntv->maxerror = tntx.maxerror;
+	ntv->esterror = tntx.esterror;
+#  ifdef NTP_API
+#   if NTP_API > 3
+	ntv->tai = tntx.tai;
+#   endif
+#  endif
+	return result;
+}
+#endif	/* !HAVE_NTP_GETTIME */
+
 #define SET_TOD_UNDETERMINED	0
 #define SET_TOD_CLOCK_SETTIME	1
 #define SET_TOD_SETTIMEOFDAY	2
diff --git a/pylib/configure.py b/pylib/configure.py
index db8ce16..921daa5 100644
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -177,6 +177,8 @@ def cmd_configure(ctx):
 		('getclock', "sys/timers.h"),
 		('getdtablesize', "unistd.h"),		# SVr4, 4.2BSD
 		('getpassphrase', "stdlib.h"),		# Sun systems
+		('ntp_adjtime', "sys/timex.h"),		# BSD
+		('ntp_gettime', "sys/timex.h"),		# BSD
 		('plock', "sys/lock.h"),		# OSF/1, SVID[23], XPG2
 		('pthread_attr_getstacksize', "pthread.h", "PTHREAD"),
 		('pthread_attr_setstacksize', "pthread.h", "PTHREAD"),



More information about the vc mailing list