Blame SOURCES/ntp-4.2.6p5-clockstate.patch

063937
diff -up ntp-4.2.6p5/ntpd/ntp_loopfilter.c.clockstate ntp-4.2.6p5/ntpd/ntp_loopfilter.c
063937
--- ntp-4.2.6p5/ntpd/ntp_loopfilter.c.clockstate	2015-12-04 13:42:45.807689201 +0100
063937
+++ ntp-4.2.6p5/ntpd/ntp_loopfilter.c	2015-12-04 15:21:34.252296997 +0100
063937
@@ -189,6 +189,51 @@ init_loopfilter(void)
063937
 	clock_jitter = LOGTOD(sys_precision);
063937
 }
063937
 
063937
+#ifdef KERNEL_PLL
063937
+/*
063937
+ * ntp_adjtime_wrapper - call ntp_adjtime() and print errors and clock state
063937
+ *                       changes related to leap seconds
063937
+ */
063937
+static int
063937
+ntp_adjtime_wrapper(struct timex *timex)
063937
+{
063937
+	static int last_ret = TIME_OK;
063937
+	int ret;
063937
+
063937
+	ret = ntp_adjtime(timex);
063937
+
063937
+	if (ret < 0) {
063937
+		msyslog(LOG_ERR, "ntp_adjtime() failed: %s", strerror(errno));
063937
+		return ret;
063937
+	}
063937
+
063937
+	if (ret == last_ret || ret == TIME_ERROR)
063937
+		return ret;
063937
+
063937
+	switch (ret) {
063937
+	case TIME_OK:
063937
+		if (last_ret != TIME_INS && last_ret != TIME_DEL)
063937
+			break;
063937
+		msyslog(LOG_INFO, "kernel leap second %s cancelled",
063937
+			last_ret == TIME_INS ? "insertion" : "deletion");
063937
+		break;
063937
+	case TIME_INS:
063937
+		msyslog(LOG_INFO, "kernel reports leap second insertion scheduled");
063937
+		break;
063937
+	case TIME_DEL:
063937
+		msyslog(LOG_INFO, "kernel reports leap second deletion scheduled");
063937
+		break;
063937
+	case TIME_WAIT:
063937
+		msyslog(LOG_INFO, "kernel reports leap second has occurred");
063937
+		break;
063937
+	}
063937
+
063937
+	last_ret = ret;
063937
+
063937
+	return ret;
063937
+}
063937
+#endif
063937
+
063937
 /*
063937
  * local_clock - the NTP logical clock loop filter.
063937
  *
063937
@@ -566,7 +611,7 @@ local_clock(
063937
 		 * the pps. In any case, fetch the kernel offset,
063937
 		 * frequency and jitter.
063937
 		 */
063937
-		if (ntp_adjtime(&ntv) == TIME_ERROR) {
063937
+		if (ntp_adjtime_wrapper(&ntv) == TIME_ERROR) {
063937
 			if (!(ntv.status & STA_PPSSIGNAL))
063937
 				report_event(EVNT_KERN, NULL,
063937
 				    "PPS no signal");
063937
@@ -598,7 +643,7 @@ local_clock(
063937
 			loop_tai = sys_tai;
063937
 			ntv.modes = MOD_TAI;
063937
 			ntv.constant = sys_tai;
063937
-			ntp_adjtime(&ntv;;
063937
+			ntp_adjtime_wrapper(&ntv;;
063937
 		}
063937
 #endif /* STA_NANO */
063937
 	}
063937
@@ -775,7 +820,7 @@ direct_freq(
063937
 	 */
063937
 	if (pll_control && kern_enable) {
063937
 		memset(&ntv,  0, sizeof(ntv));
063937
-		ntp_adjtime(&ntv;;
063937
+		ntp_adjtime_wrapper(&ntv;;
063937
 #ifdef STA_NANO
063937
 		clock_offset = ntv.offset / 1e9;
063937
 #else /* STA_NANO */
063937
@@ -811,7 +856,7 @@ set_freq(
063937
 		memset(&ntv,  0, sizeof(ntv));
063937
 		ntv.modes = MOD_FREQUENCY;
063937
 		ntv.freq = DTOFREQ(drift_comp);
063937
-		ntp_adjtime(&ntv;;
063937
+		ntp_adjtime_wrapper(&ntv;;
063937
 		snprintf(tbuf, sizeof(tbuf), "kernel %.3f PPM",
063937
 		    drift_comp * 1e6);
063937
 		report_event(EVNT_FSET, NULL, tbuf);
063937
@@ -905,7 +950,7 @@ loop_config(
063937
 			pll_control = 0;
063937
 		}
063937
 		if (sigsetjmp(env, 1) == 0)
063937
-			ntp_adjtime(&ntv;;
063937
+			ntp_adjtime_wrapper(&ntv;;
063937
 		if ((sigaction(SIGSYS, &sigsys,
063937
 		    (struct sigaction *)NULL))) {
063937
 			msyslog(LOG_ERR,
063937
@@ -913,7 +958,7 @@ loop_config(
063937
 			pll_control = 0;
063937
 		}
063937
 #else /* SIGSYS */
063937
-		ntp_adjtime(&ntv;;
063937
+		ntp_adjtime_wrapper(&ntv;;
063937
 #endif /* SIGSYS */
063937
 
063937
 		/*
063937
@@ -964,7 +1009,7 @@ loop_config(
063937
 			memset((char *)&ntv, 0, sizeof(ntv));
063937
 			ntv.modes = MOD_STATUS;
063937
 			ntv.status = STA_UNSYNC;
063937
-			ntp_adjtime(&ntv;;
063937
+			ntp_adjtime_wrapper(&ntv;;
063937
 			report_event(EVNT_KERN, NULL,
063937
  		  	    "kernel time sync disabledx");
063937
 		   }