summaryrefslogtreecommitdiff
path: root/recipes-support/ntp/files/logtime.patch
blob: bb253f48d6a0841a18b1e819e36e73875b1d2494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# The logtime test is used to compare the kernel realtime
# clock and the kernel monotonic clock, so that leap
# second may be observed.
diff -Naru old/tests/ntpd/logtime.c new/tests/ntpd/logtime.c
--- old/tests/ntpd/logtime.c	1969-12-31 18:00:00.000000000 -0600
+++ new/tests/ntpd/logtime.c	2017-05-30 13:22:11.827179154 -0500
@@ -0,0 +1,44 @@
+#include <time.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <syslog.h>
+/*
+ * Generate a log messages 4 times per second
+ * to verify leap second.  The CLOCK_MONOTONIC_RAW
+ * is the time since boot unaffected by adjustments.
+ *
+ * CLOCK_REALTIME is the UTC clock, which is affected
+ * by leap seconds.
+ *
+ * Program does not exit.
+ *
+ */
+main()
+{
+	openlog("CTST",0,LOG_LOCAL2);
+	while(1) {
+		struct timespec ts,unused,ep;
+		if (clock_gettime(CLOCK_MONOTONIC,&ts) == 0) {
+			
+			if(ts.tv_nsec < 750000000)
+				ts.tv_nsec += 250000000;
+			else {
+				ts.tv_nsec -= 750000000;
+				ts.tv_sec += 1;
+			}
+			clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&ts,&unused);	
+		        clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
+			ts.tv_nsec /= 1000000;
+		        clock_gettime(CLOCK_REALTIME,&ep);
+			ep.tv_nsec /= 1000000;
+			syslog(LOG_NOTICE,"epoch: %lu.%3.3ld  boot: %lu.%3.3ld",
+				ep.tv_sec,ep.tv_nsec,
+				ts.tv_sec,ts.tv_nsec);
+			
+		}
+		
+
+	}	
+
+}
diff -Naru old/tests/ntpd/Makefile.am new/tests/ntpd/Makefile.am
--- old/tests/ntpd/Makefile.am	2017-05-30 13:31:45.124160267 -0500
+++ new/tests/ntpd/Makefile.am	2017-05-30 16:53:59.784755988 -0500
@@ -29,6 +29,7 @@
 	test-ntp_restrict	\
 	test-ntp_scanner	\
 	test-ntp_signd		\
+        logtime		        \
 	$(NULL)
 
 
@@ -191,8 +192,8 @@
 ## check-libntp.mf - automake fragment
 ## slightly adapted for deeper directory
 
-BUILT_SOURCES	+= check-libntpd check-libntp check-libunity
-CLEANFILES	+= check-libntpd check-libntp check-libunity
+BUILT_SOURCES	+= check-libntpd check-libntp check-libunity logtime
+CLEANFILES	+= check-libntpd check-libntp check-libunity logtime
 
 check-libntpd: ../../ntpd/libntpd.a
 	@echo stamp > $@