[Git][NTPsec/ntpsec][master] 6 commits: Add contrib/make-leap-seconds.py

Hal Murray gitlab at mg.gitlab.com
Fri Mar 24 21:33:38 UTC 2017


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
b30320a4 by Hal Murray at 2017-03-24T14:33:00-07:00
Add contrib/make-leap-seconds.py

Should have been part of a previous commit.

- - - - -
16470712 by Hal Murray at 2017-03-24T14:33:00-07:00
Add --enable-debug-time to tests/option-tester.sh

Fix code to build.  Not tested at runtime.

- - - - -
9e12ab76 by Hal Murray at 2017-03-24T14:33:00-07:00
Fix typo in comment

- - - - -
df4f3b9d by Hal Murray at 2017-03-24T14:33:00-07:00
Cleanup l_fp=>time_t in ntp_filegen and ntp_util

- - - - -
8b107f2f by Hal Murray at 2017-03-24T14:33:00-07:00
Remove a few unneeded includes of ntp_fp.h

- - - - -
bf270b25 by Hal Murray at 2017-03-24T14:33:00-07:00
Couple of printf/time_t fixes

- - - - -


13 changed files:

- + contrib/make-leap-seconds.py
- include/ntp_filegen.h
- include/ntpd.h
- libntp/authkeys.c
- libntp/authreadkeys.c
- libntp/netof.c
- libntp/statestr.c
- ntpd/ntp_filegen.c
- ntpd/ntp_io.c
- ntpd/ntp_packetstamp.c
- ntpd/ntp_util.c
- ntpd/ntpd.c
- tests/option-tester.sh


Changes:

=====================================
contrib/make-leap-seconds.py
=====================================
--- /dev/null
+++ b/contrib/make-leap-seconds.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python
+"""\
+make-leap-seconds.py - make leap second file for testing
+
+Optional args are date of leap second: YYYY-MM-DD
+and expiration date of file.
+
+Defaults are start of tomorrow (UTC), and 28 days after the leap.
+"Start of tomorow" is as soon as possible for testing.
+
+"""
+# SPDX-License-Identifier: BSD-2-Clause
+from __future__ import print_function, division
+
+import sha, sys, time, datetime
+
+master_encoding = 'latin-1'
+
+if str is bytes:  # Python 2
+    polystr = str
+    polybytes = bytes
+
+    def string_escape(s):
+        return s.decode('string_escape')
+
+    def make_wrapper(fp):
+        return fp
+
+else:  # Python 3
+    import io
+
+    def polystr(o):
+        "Polymorphic string factory function"
+        if isinstance(o, str):
+            return o
+        if not isinstance(o, bytes):
+            return str(o)
+        return str(o, encoding=master_encoding)
+
+    def polybytes(s):
+        "Polymorphic string encoding function"
+        if isinstance(s, bytes):
+            return s
+        if not isinstance(s, str):
+            return bytes(s)
+        return bytes(s, encoding=master_encoding)
+
+    def string_escape(s):
+        "Polymorphic string_escape/unicode_escape"
+        # This hack is necessary because Unicode strings in Python 3 don't
+        # have a decode method, so there's no simple way to ask it for the
+        # equivalent of decode('string_escape') in Python 2. This function
+        # assumes that it will be called with a Python 3 'str' instance
+        return s.encode(master_encoding).decode('unicode_escape')
+
+    def make_wrapper(fp):
+        "Wrapper factory function to enforce master encoding"
+        # This can be used to wrap normally binary streams for API
+        # compatibility with functions that need a text stream in
+        # Python 3; it ensures that the binary bytes are decoded using
+        # the master encoding we use to turn bytes to Unicode in
+        # polystr above
+        # newline="\n" ensures that Python 3 won't mangle line breaks
+        return io.TextIOWrapper(fp, encoding=master_encoding, newline="\n")
+
+    def make_std_wrapper(stream):
+        "Standard input/output wrapper factory function"
+        # This ensures that the encoding of standard output and standard
+        # error on Python 3 matches the master encoding we use to turn
+        # bytes to Unicode in polystr above
+        # line_buffering=True ensures that interactive command sessions
+        # work as expected
+        return io.TextIOWrapper(stream.buffer, encoding=master_encoding,
+                                newline="\n", line_buffering=True)
+
+    sys.stdin = make_std_wrapper(sys.stdin)
+    sys.stdout = make_std_wrapper(sys.stdout)
+    sys.stderr = make_std_wrapper(sys.stderr)
+
+JAN_1970 = 2208988800   # convert Unix/POSIX epoch to NTP epoch
+epoch = datetime.datetime.utcfromtimestamp(0)
+args = sys.argv[1:]
+
+leap = time.time()
+days = int(leap/86400)
+leap = days*86400
+
+if len(args) > 0:
+  leapdate = datetime.datetime.strptime(args[0], "%Y-%m-%d")
+  leap = (leapdate - epoch).total_seconds()
+  leap = int(leap)
+  args = args[1:]
+
+expire = leap + 28*86400
+if len(args) > 0:
+  expiredate = datetime.datetime.strptime(args[0], "%Y-%m-%d")
+  expire = (expiredate - epoch).total_seconds()
+  expire = int(expire)
+  args = args[1:]
+leap = str(leap+JAN_1970)
+expire=str(expire+JAN_1970)
+
+update = time.time()
+days = int(update/86400)
+update = days*86400
+update = str(update+JAN_1970)
+tai = "40"          # hardwired
+
+# File format
+#
+#  # is comment
+#  #$ xxx  Update Date
+#  #@ xxx  Expiration Date
+#  #h SHA1 hash of payload
+#
+#  #$       3676924800
+#  #@       3707596800
+#  2272060800      10      # 1 Jan 1972
+#  #h      dacf2c42 2c4765d6 3c797af8 2cf630eb 699c8c67
+#
+#  All dates use NTP epoch of 1900-01-01
+
+sha1 = sha.new()
+print("%s %s" % (leap, tai))
+sha1.update(leap)
+sha1.update(tai)
+print("#$ %s" % update)
+sha1.update(update)
+print("#@ %s" % expire)
+sha1.update(expire)
+digest = sha1.hexdigest()
+print("#h %s %s %s %s %s" % \
+ (digest[0:8], digest[8:16], digest[16:24], digest[24:32], digest[32:40]))
+
+# end


=====================================
include/ntp_filegen.h
=====================================
--- a/include/ntp_filegen.h
+++ b/include/ntp_filegen.h
@@ -35,13 +35,13 @@ typedef struct filegen_tag {
 	char *	dir;	/* currently always statsdir */
 	char *	fname;	/* filename prefix of generation file */
 			/* must be malloced, will be fed to free() */
-	u_long	id_lo;	/* lower bound of ident value */
-	u_long	id_hi;	/* upper bound of ident value */
+	time_t	id_lo;	/* lower bound of ident value */
+	time_t	id_hi;	/* upper bound of ident value */
 	uint8_t	type;	/* type of file generation */
 	uint8_t	flag;	/* flags modifying processing of file generation */
 } FILEGEN;
 
-extern	void	filegen_setup	(FILEGEN *, uint32_t);
+extern	void	filegen_setup	(FILEGEN *, time_t);
 extern	void	filegen_config	(FILEGEN *, const char *, const char *,
 				 u_int, u_int);
 extern	void	filegen_statsdir(void);


=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -115,8 +115,8 @@ extern  SOCKET	open_socket	(sockaddr_u *, bool, bool, endpt *);
 extern	void	io_open_sockets	(void);
 extern	void	io_clr_stats	(void);
 extern	void	sendpkt 	(sockaddr_u *, endpt *, void *, int);
-#ifdef DEBUG
-extern	void	collect_timing  (struct recvbuf *, const char *, int, l_fp *);
+#ifdef ENABLE_DEBUG_TIMING
+extern	void	collect_timing  (struct recvbuf *, const char *, int, l_fp);
 #endif
 #define		latoa(pif)	localaddrtoa(pif)
 extern const char * localaddrtoa(endpt *);
@@ -231,7 +231,7 @@ extern	int	mprintf_clock_stats(struct peer *, const char *, ...)
 extern	void	record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int ppoll, int precision, double root_delay, double root_dispersion, uint32_t refid, u_int outcount);
 extern	void	check_leap_file	(bool is_daily_check, time_t systime);
 extern	void	record_crypto_stats (sockaddr_u *, const char *);
-#ifdef DEBUG
+#ifdef ENABLE_DEBUG_TIMING
 extern	void	record_timing_stats (const char *);
 #endif
 


=====================================
libntp/authkeys.c
=====================================
--- a/libntp/authkeys.c
+++ b/libntp/authkeys.c
@@ -8,7 +8,6 @@
 #include <string.h>
 
 #include "ntp.h"
-#include "ntp_fp.h"
 #include "ntpd.h"
 #include "ntp_lists.h"
 #include "ntp_malloc.h"


=====================================
libntp/authreadkeys.c
=====================================
--- a/libntp/authreadkeys.c
+++ b/libntp/authreadkeys.c
@@ -5,7 +5,6 @@
 #include <stdio.h>
 #include <ctype.h>
 
-#include "ntp_fp.h"
 #include "ntp.h"
 #include "ntp_syslog.h"
 #include "ntp_stdlib.h"


=====================================
libntp/netof.c
=====================================
--- a/libntp/netof.c
+++ b/libntp/netof.c
@@ -6,7 +6,6 @@
 #include <stdio.h>
 #include <syslog.h>
 
-#include "ntp_fp.h"
 #include "ntp_net.h"
 #include "ntp_stdlib.h"
 #include "ntp.h"


=====================================
libntp/statestr.c
=====================================
--- a/libntp/statestr.c
+++ b/libntp/statestr.c
@@ -8,7 +8,6 @@
 #include <string.h>
 
 #include "ntp_stdlib.h"
-#include "ntp_fp.h"
 #include "ntp.h"
 #include "lib_strbuf.h"
 #include "ntp_refclock.h"


=====================================
ntpd/ntp_filegen.c
=====================================
--- a/ntpd/ntp_filegen.c
+++ b/ntpd/ntp_filegen.c
@@ -39,7 +39,7 @@
  */
 #define SUFFIX_SEP '.'
 
-static	void	filegen_open	(FILEGEN *, uint32_t, const time_t*);
+static	void	filegen_open	(FILEGEN *, const time_t);
 static	int	valid_fileref	(const char *, const char *);
 static	void	filegen_init	(const char *, const char *, FILEGEN *);
 #ifdef	DEBUG
@@ -91,8 +91,7 @@ filegen_uninit(
 static void
 filegen_open(
 	FILEGEN *	gen,
-	uint32_t		stamp,
-	const time_t *	pivot
+	const time_t 	stamp
 	)
 {
 	char *savename;	/* temp store for name collision handling */
@@ -101,8 +100,7 @@ filegen_open(
 	char *suffix;	/* where to print suffix extension */
 	u_int len, suflen;
 	FILE *fp;
-	struct calendar cal;
-	struct isodate	iso;
+	struct tm tm;
 
 	/* get basic filename in buffer, leave room for extensions */
 	len = strlen(gen->dir) + strlen(gen->fname) + 65;
@@ -136,8 +134,8 @@ filegen_open(
 	case FILEGEN_PID:
 		gen->id_lo = getpid();
 		gen->id_hi = 0;
-		snprintf(suffix, suflen, "%c#%ld",
-			 SUFFIX_SEP, gen->id_lo);
+		snprintf(suffix, suflen, "%c#%lld",
+			 SUFFIX_SEP, (long long)gen->id_lo);
 		break;
 
 	case FILEGEN_DAY:
@@ -146,51 +144,49 @@ filegen_open(
 		 * would assume it to be easier for humans to interpret
 		 * dates in a format they are used to in everyday life.
 		 */
-		ntpcal_ntp_to_date(&cal, stamp, pivot);
+		gmtime_r(&stamp, &tm);
 		snprintf(suffix, suflen, "%c%04d%02d%02d",
-			 SUFFIX_SEP, cal.year, cal.month, cal.monthday);
-		cal.hour = cal.minute = cal.second = 0;
-		gen->id_lo = ntpcal_date_to_ntp(&cal); 
-		gen->id_hi = (uint32_t)(gen->id_lo + SECSPERDAY);
+			 SUFFIX_SEP, tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
+		gen->id_lo = stamp - (stamp % SECSPERDAY);
+		gen->id_hi = gen->id_lo + SECSPERDAY;
 		break;
 
 	case FILEGEN_WEEK:
-		isocal_ntp_to_date(&iso, stamp, pivot);
+		/* week number is day-of-year mod 7 */
+		gmtime_r(&stamp, &tm);
 		snprintf(suffix, suflen, "%c%04dw%02d",
-			 SUFFIX_SEP, iso.year, iso.week);
-		iso.hour = iso.minute = iso.second = 0;
-		iso.weekday = 1;
-		gen->id_lo = isocal_date_to_ntp(&iso);
-		gen->id_hi = (uint32_t)(gen->id_lo + 7 * SECSPERDAY);
+			 SUFFIX_SEP, tm.tm_year+1900, tm.tm_yday % 7);
+		/* See comment below at MONTH */
+		gen->id_lo = stamp - (stamp % SECSPERDAY);
+		gen->id_hi = gen->id_lo + SECSPERDAY;
 		break;
 
 	case FILEGEN_MONTH:
-		ntpcal_ntp_to_date(&cal, stamp, pivot);
+		gmtime_r(&stamp, &tm);
 		snprintf(suffix, suflen, "%c%04d%02d",
-			 SUFFIX_SEP, cal.year, cal.month);
-		cal.hour = cal.minute = cal.second = 0;
-		cal.monthday = 1;
-		gen->id_lo = ntpcal_date_to_ntp(&cal); 
-		cal.month++;
-		gen->id_hi = ntpcal_date_to_ntp(&cal); 
+			 SUFFIX_SEP, tm.tm_year+1900, tm.tm_mon+1);
+		/* If we had a mktime that didn't use the local time zone
+		 * we could setup id_lo and id_hi to bracket the month.
+		 * This will have to recalculate things each day.
+		 */
+		gen->id_lo = stamp - (stamp % SECSPERDAY);
+		gen->id_hi = gen->id_lo + SECSPERDAY;
 		break;
 
 	case FILEGEN_YEAR:
-		ntpcal_ntp_to_date(&cal, stamp, pivot);
+		gmtime_r(&stamp, &tm);
 		snprintf(suffix, suflen, "%c%04d",
-			 SUFFIX_SEP, cal.year);
-		cal.hour = cal.minute = cal.second = 0;
-		cal.month = cal.monthday = 1;
-		gen->id_lo = ntpcal_date_to_ntp(&cal); 
-		cal.year++;
-		gen->id_hi = ntpcal_date_to_ntp(&cal); 
+			 SUFFIX_SEP, tm.tm_year+1900);
+		/* See comment above at MONTH */
+		gen->id_lo = stamp - (stamp % SECSPERDAY);
+		gen->id_hi = gen->id_lo + SECSPERDAY;
 		break;
 
 	case FILEGEN_AGE:
 		gen->id_lo = current_time - (current_time % SECSPERDAY);
 		gen->id_hi = gen->id_lo + SECSPERDAY;
-		snprintf(suffix, suflen, "%ca%08ld",
-			 SUFFIX_SEP, gen->id_lo);
+		snprintf(suffix, suflen, "%ca%08lld",
+			 SUFFIX_SEP, (long long)gen->id_lo);
 	}
   
 	/* check possible truncation */
@@ -269,8 +265,8 @@ filegen_open(
 	/*
 	 * now, try to open new file generation...
 	 */
-	DPRINTF(4, ("opening filegen (type=%d/stamp=%u) \"%s\"\n",
-		    gen->type, stamp, fullname));
+	DPRINTF(4, ("opening filegen (type=%d/stamp=%lld) \"%s\"\n",
+		    gen->type, (long long)stamp, fullname));
 
 	fp = fopen(fullname, "a");
   
@@ -320,19 +316,15 @@ filegen_open(
 /*
  * this function sets up gen->fp to point to the correct
  * generation of the file for the time specified by 'now'
- *
- * 'now' usually is interpreted as second part of a l_fp as is in the cal...
- * library routines
  */
 
 void
 filegen_setup(
-	FILEGEN *	gen,
-	uint32_t		now
+	FILEGEN * gen,
+	time_t now
 	)
 {
 	bool	current;
-	time_t	pivot;
 
 	if (!(gen->flag & FGEN_FLAG_ENABLED)) {
 		if (NULL != gen->fp) {
@@ -354,8 +346,8 @@ filegen_setup(
 		break;
 
 	case FILEGEN_AGE:
-		current = (gen->id_lo <= current_time) &&
-			  (gen->id_hi > current_time);
+		current = (gen->id_lo <= (long)current_time) &&
+			  (gen->id_hi > (long)current_time);
 		break;
 
 	case FILEGEN_DAY:
@@ -371,9 +363,8 @@ filegen_setup(
 	 * reopen new file generation file on change of generation id
 	 */
 	if (NULL == gen->fp || !current) {
-		DPRINTF(1, ("filegen  %0x %u\n", gen->type, now));
-		pivot = time(NULL);
-		filegen_open(gen, now, &pivot);
+		DPRINTF(1, ("filegen  %0x %lld\n", gen->type, (long long)now));
+		filegen_open(gen, now);
 	}
 }
 
@@ -391,7 +382,6 @@ filegen_config(
 	)
 {
 	bool file_existed;
-	l_fp now;
 
 
 	/*
@@ -444,8 +434,7 @@ filegen_config(
 	 * otherwise the new settings will be used anyway at the next open
 	 */
 	if (file_existed) {
-		get_systime(&now);
-		filegen_setup(gen, lfpuint(now));
+		filegen_setup(gen, time(NULL));
 	}
 }
 


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -302,11 +302,11 @@ maintain_activefds(
  * collect timing information for various processing
  * paths. currently we only pass them on to the file
  * for later processing. this could also do histogram
- * based analysis in other to reduce the load (and skew)
- * dur to the file output
+ * based analysis in order to reduce the load (and skew)
+ * due to the file output
  */
 void
-collect_timing(struct recvbuf *rb, const char *tag, int count, l_fp *dts)
+collect_timing(struct recvbuf *rb, const char *tag, int count, l_fp dts)
 {
 	char buf[256];
 
@@ -2574,11 +2574,11 @@ input_handler(
 	 * gob of file descriptors.  Log it.
 	 */
 	ts_e -= ts;
-	collect_timing(NULL, "input handler", 1, &ts_e);
+	collect_timing(NULL, "input handler", 1, ts_e);
 	if (debug > 3)
 		msyslog(LOG_DEBUG,
 			"input_handler: Processed a gob of fd's in %s msec",
-			lfptoms(&ts_e, 6));
+			lfptoms(ts_e, 6));
 #endif /* ENABLE_DEBUG_TIMING */
 	/* We're done... */
 	return;


=====================================
ntpd/ntp_packetstamp.c
=====================================
--- a/ntpd/ntp_packetstamp.c
+++ b/ntpd/ntp_packetstamp.c
@@ -202,10 +202,9 @@ fetch_packetstamp(
 #ifdef ENABLE_DEBUG_TIMING
 			dts = ts;
 			dts -= nts;
-			collect_timing(rb, "input processing delay", 1,
-				       &dts);
+			collect_timing(rb, "input processing delay", 1, dts);
 			DPRINTF(4, ("fetch_timestamp: timestamp delta: %s (incl. fuzz)\n",
-				    lfptoa(&dts, 9)));
+				    lfptoa(dts, 9)));
 #endif	/* ENABLE_DEBUG_TIMING */
 			ts = nts;  /* network time stamp */
 			break;


=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -26,9 +26,9 @@
 #endif
 
 /*
- * Defines used by the leapseconds stuff
+ * Defines used by file logging
  */
-#define MJD_1900		15020	/* MJD for 1 Jan 1900 */
+#define MJD_1970        40587           /* MJD for 1 Jan 1970 */
 
 /*
  * This contains odds and ends, including the hourly stats, various
@@ -202,9 +202,6 @@ write_stats(void)
 }
 
 
-/*
- * stats_config - configure the stats operation
- */
 static bool drift_read(const char *drift_file, double *drift)
 {
 	FILE *fp;
@@ -222,6 +219,9 @@ static bool drift_read(const char *drift_file, double *drift)
 	return true;
 }
 
+/*
+ * stats_config - configure the stats operation
+ */
 void
 stats_config(
 	int item,
@@ -347,6 +347,26 @@ stats_config(
 	}
 }
 
+/* timespec_to_MJDtime
+ */
+
+char *
+timespec_to_MJDtime(const struct timespec *time)
+{
+	char *buf;
+	u_long	day, sec, msec;
+
+	LIB_GETBUF(buf);
+
+	day = time->tv_sec / 86400 + MJD_1970;
+	sec = time->tv_sec % 86400;
+	msec = time->tv_nsec/1000000;  /* nano seconds to milliseconds */
+	snprintf(buf, LIB_BUFLENGTH, "%lu %lu.%03ld", day, sec, msec);
+
+	return buf;
+}
+
+
 /*
  * record_peer_stats - write peer statistics to file
  *
@@ -366,20 +386,18 @@ record_peer_stats(
 	int	status
 	)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&peerstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&peerstats, now.tv_sec);
 	if (peerstats.fp != NULL) {
 		fprintf(peerstats.fp,
-		    "%lu %s %s %x %.9f %.9f %.9f %.9f\n", day,
-		    ulfptoa(now, 3), socktoa(&peer->srcadr), status, peer->offset,
+		    "%s %s %x %.9f %.9f %.9f %.9f\n",
+		    timespec_to_MJDtime(&now),
+		    socktoa(&peer->srcadr), status, peer->offset,
 		    peer->delay, peer->disp, peer->jitter);
 		fflush(peerstats.fp);
 	}
@@ -417,19 +435,17 @@ record_loop_stats(
 	int spoll
 	)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&loopstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&loopstats, now.tv_sec);
 	if (loopstats.fp != NULL) {
-		fprintf(loopstats.fp, "%lu %s %.9f %.6f %.9f %.6f %d\n",
-		    day, ulfptoa(now, 3), offset, freq * US_PER_S, jitter,
+		fprintf(loopstats.fp, "%s %.9f %.6f %.9f %.6f %d\n",
+		    timespec_to_MJDtime(&now),
+		    offset, freq * US_PER_S, jitter,
 		    wander * US_PER_S, spoll);
 		fflush(loopstats.fp);
 	}
@@ -451,19 +467,16 @@ record_clock_stats(
 	const char *text	/* timecode string */
 	)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&clockstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&clockstats, now.tv_sec);
 	if (clockstats.fp != NULL) {
-		fprintf(clockstats.fp, "%lu %s %s %s\n", day,
-		    ulfptoa(now, 3), peerlabel(peer), text);
+		fprintf(clockstats.fp, "%s %s %s\n",
+		    timespec_to_MJDtime(&now), peerlabel(peer), text);
 		fflush(clockstats.fp);
 	}
 }
@@ -523,19 +536,16 @@ record_raw_stats(
 	u_int	outcount
 	)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&rawstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&rawstats, now.tv_sec);
 	if (rawstats.fp != NULL) {
-		fprintf(rawstats.fp, "%lu %s %s %s %s %s %s %s %d %d %d %d %d %d %.6f %.6f %s %d\n",
-		    day, ulfptoa(now, 3),
+		fprintf(rawstats.fp, "%s %s %s %s %s %s %s %d %d %d %d %d %d %.6f %.6f %s %d\n",
+		    timespec_to_MJDtime(&now),
 		    socktoa(srcadr), dstadr ?  socktoa(dstadr) : "-",
 		    ulfptoa(*t1, 9), ulfptoa(*t2, 9),
 		    ulfptoa(*t3, 9), ulfptoa(*t4, 9),
@@ -568,20 +578,17 @@ record_raw_stats(
 void
 record_sys_stats(void)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&sysstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&sysstats, now.tv_sec);
 	if (sysstats.fp != NULL) {
 		fprintf(sysstats.fp,
-		    "%lu %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
-		    day, ulfptoa(now, 3), current_time - sys_stattime,
+		    "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+		    timespec_to_MJDtime(&now), current_time - sys_stattime,
 		    sys_received, sys_processed, sys_newversion,
 		    sys_oldversion, sys_restricted, sys_badlength,
 		    sys_badauth, sys_declined, sys_limitrejected,
@@ -603,8 +610,7 @@ record_sys_stats(void)
 void record_use_stats(void)
 {
 #ifdef HAVE_GETRUSAGE
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 	struct rusage usage;
 	static struct rusage oldusage;
 	/* Descriptions in NetBSD and FreeBSD are better than Linux
@@ -613,10 +619,8 @@ void record_use_stats(void)
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&usestats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&usestats, now.tv_sec);
 	if (usestats.fp != NULL) {
 		double utime, stime;
 		getrusage(RUSAGE_SELF, &usage);
@@ -627,8 +631,8 @@ void record_use_stats(void)
 		stime /= 1E6;
 		stime += usage.ru_stime.tv_sec -  oldusage.ru_stime.tv_sec;
 		fprintf(usestats.fp,
-		    "%lu %s %lu %.3f %.3f %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
-		    day, ulfptoa(now, 3), current_time - use_stattime,
+		    "%s %lu %.3f %.3f %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+		    timespec_to_MJDtime(&now), current_time - use_stattime,
 		    utime, stime,
 		    usage.ru_minflt -   oldusage.ru_minflt,
 		    usage.ru_majflt -   oldusage.ru_majflt,
@@ -660,19 +664,16 @@ record_proto_stats(
 	char	*str		/* text string */
 	)
 {
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&protostats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&protostats, now.tv_sec);
 	if (protostats.fp != NULL) {
-		fprintf(protostats.fp, "%lu %s %s\n", day,
-		    ulfptoa(now, 3), str);
+		fprintf(protostats.fp, "%s %s\n",
+		    timespec_to_MJDtime(&now), str);
 		fflush(protostats.fp);
 	}
 }
@@ -692,19 +693,16 @@ record_timing_stats(
 	)
 {
 	static unsigned int flshcnt;
-	l_fp	now;
-	u_long	day;
+	struct timespec	now;
 
 	if (!stats_control)
 		return;
 
-	get_systime(&now);
-	filegen_setup(&timingstats, lfpuint(now));
-	day = lfpuint(now) / 86400 + MJD_1900;
-	setlfpuint(now, lfpuint(now) % 86400);
+	clock_gettime(CLOCK_REALTIME, &now);
+	filegen_setup(&timingstats, now.tv_sec);
 	if (timingstats.fp != NULL) {
-		fprintf(timingstats.fp, "%lu %s %s\n", day, lfptoa(now,
-		    3), text);
+		fprintf(timingstats.fp, "%s %s\n",
+		    timespec_to_MJDtime(&now), text);
 		if (++flshcnt % 100 == 0)
 			fflush(timingstats.fp);
 	}


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -895,8 +895,8 @@ static void mainloop(void)
 					l_fp dts = pts;
 
 					dts -= rbuf->recv_time;
-					DPRINTF(2, ("processing timestamp delta %s (with prec. fuzz)\n", lfptoa(&dts, 9)));
-					collect_timing(rbuf, "buffer processing delay", 1, &dts);
+					DPRINTF(2, ("processing timestamp delta %s (with prec. fuzz)\n", lfptoa(dts, 9)));
+					collect_timing(rbuf, "buffer processing delay", 1, dts);
 					bufcount++;
 # endif
 					(*rbuf->receiver)(rbuf);
@@ -912,8 +912,8 @@ static void mainloop(void)
 			get_systime(&tsb);
 			tsb -= tsa;
 			if (bufcount) {
-				collect_timing(NULL, "processing", bufcount, &tsb);
-				DPRINTF(2, ("processing time for %d buffers %s\n", bufcount, lfptoa(&tsb, 9)));
+				collect_timing(NULL, "processing", bufcount, tsb);
+				DPRINTF(2, ("processing time for %d buffers %s\n", bufcount, lfptoa(tsb, 9)));
 			}
 		}
 # endif


=====================================
tests/option-tester.sh
=====================================
--- a/tests/option-tester.sh
+++ b/tests/option-tester.sh
@@ -39,7 +39,7 @@ doit ()
 
 doit minimal "--disable-debug --disable-droproot --disable-dns-lookup --disable-kernel-pll --disable-mdns-registration"
 doit nodebug "--disable-debug --refclock=all"
-doit all     "--enable-lockclock --enable-leap-smear --enable-mssntp --refclock=all"
+doit all     "--enable-lockclock --enable-leap-smear --enable-mssntp --enable-debug-timing --refclock=all"
 
 if [ `uname -s` = Linux ]
 then



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/ac220ef9dfd1d3c7aebec34c3bbf3e0901d406d6...bf270b2569cb3a7ae0a4f6a2abe6b8550ada2e78
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170324/1468512e/attachment.html>


More information about the vc mailing list