[Git][NTPsec/ntpsec][deglobal] De-globaled clock control flags.

Ian Bruene gitlab at mg.gitlab.com
Sun May 20 22:20:02 UTC 2018


Ian Bruene pushed to branch deglobal at NTPsec / ntpsec


Commits:
c2eb57fd by Ian Bruene at 2018-05-20T22:19:04Z
De-globaled clock control flags.

- - - - -


10 changed files:

- include/ntpd.h
- ntpd/ntp_config.c
- ntpd/ntp_loopfilter.c
- ntpd/ntp_peer.c
- ntpd/ntp_proto.c
- ntpd/ntp_refclock.c
- ntpd/ntp_timer.c
- ntpd/ntpd.c
- ntpd/refclock_generic.c
- ntpd/refclock_oncore.c


Changes:

=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -263,14 +263,17 @@ extern double	clock_phi;		/* dispersion rate (s/s) */
 /*
  * Clock state machine control flags
  */
-extern bool	ntp_enable;		/* clock discipline enabled */
-extern bool	pll_control;		/* kernel support available */
-extern bool	kern_enable;		/* kernel support enabled */
-extern bool	hardpps_enable;		/* kernel PPS discipline enabled */
+struct clock_control_flags {
+    bool	ntp_enable;		/* clock discipline enabled */
+    bool	pll_control;		/* kernel support available */
+    bool	kern_enable;		/* kernel support enabled */
+    bool	hardpps_enable;		/* kernel PPS discipline enabled */
+    bool	allow_panic;		/* allow panic correction (-g) */
+    bool	force_step_once;	/* always step time once at startup (-G) */
+    bool	mode_ntpdate;		/* exit on first clock set (-q) */
+};
+extern struct clock_control_flags clock_ctl;
 extern bool	cal_enable;		/* refclock calibrate enable */
-extern bool	allow_panic;		/* allow panic correction (-g) */
-extern bool	force_step_once;	/* always step time once at startup (-G) */
-extern bool	mode_ntpdate;		/* exit on first clock set (-q) */
 extern int	peer_ntpdate;		/* count of ntpdate peers */
 
 /*


=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -2616,7 +2616,7 @@ peer_config(
 	 * are.
 	 */
 	ctl->flags |= FLAG_CONFIG;
-	if (mode_ntpdate)
+	if (clock_ctl.mode_ntpdate)
 		ctl->flags |= FLAG_IBURST;
 	return newpeer(srcadr, hostname, dstadr, hmode,
 		       ctl, cast_flags, true);


=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -148,13 +148,15 @@ static	void	stop_kern_loop(void);
 /*
  * Clock state machine control flags
  */
-bool	ntp_enable = true;	/* clock discipline enabled */
-bool	pll_control = false;	/* kernel support available */
-bool	kern_enable = true;	/* kernel support enabled */
-bool	hardpps_enable;		/* kernel PPS discipline enabled */
-bool	allow_panic = false;	/* allow panic correction (-g) */
-bool	force_step_once = false; /* always step time once at startup (-G) */
-bool	mode_ntpdate = false;	/* exit on first clock set (-q) */
+struct clock_control_flags clock_ctl = {
+	.ntp_enable = true,	/* clock discipline enabled */
+	.pll_control = false,	/* kernel support available */
+	.kern_enable = true,	/* kernel support enabled */
+	.hardpps_enable = false,		/* kernel PPS discipline enabled */
+	.allow_panic = false,	/* allow panic correction (-g) */
+	.force_step_once = false, /* always step time once at startup (-G) */
+	.mode_ntpdate = false	/* exit on first clock set (-q) */
+};
 int	freq_cnt;		/* initial frequency clamp */
 
 static int freq_set;		/* initial set frequency switch */
@@ -466,7 +468,7 @@ local_clock(
 #ifdef ENABLE_LOCKCLOCK
 	{
 #else
-	if (!ntp_enable) {
+	if (!clock_ctl.ntp_enable) {
 #endif /* ENABLE_LOCKCLOCK */
 		record_loop_stats(fp_offset, drift_comp, clock_jitter,
 		    clock_stability, sys_poll);
@@ -484,7 +486,7 @@ local_clock(
 	 * than the step threshold; so, subsequent panics will exit.
 	 */
 	if (fabs(fp_offset) > clock_panic && clock_panic > 0 &&
-	    !allow_panic) {
+	    !clock_ctl.allow_panic) {
 		snprintf(tbuf, sizeof(tbuf),
 		    "%+.0f s; set clock manually within %.0f s.",
 		    fp_offset, clock_panic);
@@ -501,7 +503,7 @@ local_clock(
 	 * terminal does not detach, so the termination message prints
 	 * directly to the terminal.
 	 */
-	if (mode_ntpdate) {
+	if (clock_ctl.mode_ntpdate) {
 		if (  ( fp_offset > clock_max_fwd  && clock_max_fwd  > 0)
 		   || (-fp_offset > clock_max_back && clock_max_back > 0)) {
 			step_systime(fp_offset, ntp_set_tod);
@@ -563,9 +565,9 @@ local_clock(
 	rval = 1;
 	if (  ( fp_offset > clock_max_fwd  && clock_max_fwd  > 0)
 	   || (-fp_offset > clock_max_back && clock_max_back > 0)
-	   || force_step_once ) {
-		if (force_step_once) {
-			force_step_once = false;  /* we want this only once after startup */
+	   || clock_ctl.force_step_once ) {
+		if (clock_ctl.force_step_once) {
+			clock_ctl.force_step_once = false;  /* we want this only once after startup */
 			msyslog(LOG_NOTICE, "CLOCK: Doing intital time step" );
 		}
 
@@ -687,7 +689,7 @@ local_clock(
 		 * startup until the initial transient has subsided.
 		 */
 		default:
-			allow_panic = false;
+			clock_ctl.allow_panic = false;
 			if (freq_cnt == 0) {
 
 				/*
@@ -735,7 +737,7 @@ local_clock(
 	 * lead to overflow problems. This might occur if some misguided
 	 * lad set the step threshold to something ridiculous.
 	 */
-	if (pll_control && kern_enable && freq_cnt == 0) {
+	if (clock_ctl.pll_control && clock_ctl.kern_enable && freq_cnt == 0) {
 		static int kernel_status;	/* from ntp_adjtime */
 
 		/*
@@ -779,7 +781,7 @@ local_clock(
 			/*
 			 * Enable/disable the PPS if requested.
 			 */
-			if (hardpps_enable) {
+			if (clock_ctl.hardpps_enable) {
 				ntv.status |= (STA_PPSTIME | STA_PPSFREQ);
 				if (!(pll_status & STA_PPSTIME))
 					sync_status("PPS enabled",
@@ -808,7 +810,7 @@ local_clock(
 		 */
 		if ((0 > ntp_adj_ret) || (ntp_adj_ret != kernel_status)) {
 			kernel_status = ntp_adj_ret;
-			ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, hardpps_enable, false, __LINE__ - 1);
+			ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, clock_ctl.hardpps_enable, false, __LINE__ - 1);
 		}
 		pll_status = ntv.status;
 		clock_offset = ntv.offset * S_PER_NS;
@@ -935,7 +937,7 @@ adj_host_clock(
 	 */
 	sys_vars.sys_rootdisp += clock_phi;
 #ifndef ENABLE_LOCKCLOCK
-	if (!ntp_enable || mode_ntpdate)
+	if (!clock_ctl.ntp_enable || clock_ctl.mode_ntpdate)
 		return;
 	/*
 	 * Determine the phase adjustment. The gain factor (denominator)
@@ -948,7 +950,7 @@ adj_host_clock(
 	} else if (freq_cnt > 0) {
 		offset_adj = clock_offset / (CLOCK_PLL * ULOGTOD(1));
 		freq_cnt--;
-	} else if (pll_control && kern_enable) {
+	} else if (clock_ctl.pll_control && clock_ctl.kern_enable) {
 		offset_adj = 0.;
 	} else {
 		offset_adj = clock_offset / (CLOCK_PLL * ULOGTOD(sys_poll));
@@ -960,7 +962,7 @@ adj_host_clock(
 	 * set_freq().  Otherwise it is a component of the adj_systime()
 	 * offset.
 	 */
-	if (pll_control && kern_enable)
+	if (clock_ctl.pll_control && clock_ctl.kern_enable)
 		freq_adj = 0.;
 	else
 		freq_adj = drift_comp;
@@ -1054,11 +1056,11 @@ set_freq(
 
 	drift_comp = freq;
 	loop_desc = "ntpd";
-	if (pll_control) {
+	if (clock_ctl.pll_control) {
 		int ntp_adj_ret;
 		ZERO(ntv);
 		ntv.modes = MOD_FREQUENCY;
-		if (kern_enable) {
+		if (clock_ctl.kern_enable) {
 			loop_desc = "kernel";
 			ntv.freq = DTOFREQ(drift_comp);
 		}
@@ -1077,7 +1079,7 @@ start_kern_loop(void)
 	static bool atexit_done;
 	int ntp_adj_ret;
 
-	pll_control = true;
+	clock_ctl.pll_control = true;
 	ZERO(ntv);
 	ntv.modes = MOD_BITS;
 	ntv.status = STA_PLL;
@@ -1094,7 +1096,7 @@ start_kern_loop(void)
 	newsigsys.sa_flags = 0;
 	if (sigaction(SIGSYS, &newsigsys, &sigsys)) {
 		msyslog(LOG_ERR, "ERR: sigaction() trap SIGSYS: %m");
-		pll_control = false;
+		clock_ctl.pll_control = false;
 	} else {
 		if (sigsetjmp(env, 1) == 0) {
 			if ((ntp_adj_ret = ntp_adjtime_ns(&ntv)) != 0) {
@@ -1104,7 +1106,7 @@ start_kern_loop(void)
 		if (sigaction(SIGSYS, &sigsys, NULL)) {
 			msyslog(LOG_ERR,
 			    "ERR: sigaction() restore SIGSYS: %m");
-			pll_control = false;
+			clock_ctl.pll_control = false;
 		}
 	}
 #else /* SIGSYS */
@@ -1118,7 +1120,7 @@ start_kern_loop(void)
 	 * if available.
 	 */
 	pll_status = ntv.status;
-	if (pll_control) {
+	if (clock_ctl.pll_control) {
 		if (!atexit_done) {
 			atexit_done = true;
 			atexit(&stop_kern_loop);
@@ -1136,7 +1138,7 @@ start_kern_loop(void)
 static void
 stop_kern_loop(void)
 {
-	if (pll_control && kern_enable)
+	if (clock_ctl.pll_control && clock_ctl.kern_enable)
 		report_event(EVNT_KERN, NULL,
 		    "kernel time sync disabled");
 }
@@ -1150,12 +1152,12 @@ select_loop(
 	int	use_kern_loop
 	)
 {
-	if (kern_enable == use_kern_loop)
+	if (clock_ctl.kern_enable == use_kern_loop)
 		return;
-	if (pll_control && !use_kern_loop)
+	if (clock_ctl.pll_control && !use_kern_loop)
 		stop_kern_loop();
-	kern_enable = use_kern_loop;
-	if (pll_control && use_kern_loop)
+	clock_ctl.kern_enable = use_kern_loop;
+	if (clock_ctl.pll_control && use_kern_loop)
 		start_kern_loop();
 	/*
 	 * If this loop selection change occurs after initial startup,
@@ -1163,7 +1165,7 @@ select_loop(
 	 * from the kernel loop.
 	 */
 #if !defined(ENABLE_LOCKCLOCK)
-	if (pll_control && loop_started)
+	if (clock_ctl.pll_control && loop_started)
 		set_freq(drift_comp);
 #endif
 }
@@ -1213,7 +1215,7 @@ loop_config(
 	 */
 	case LOOP_DRIFTINIT:
 #ifndef ENABLE_LOCKCLOCK
-		if (mode_ntpdate)
+		if (clock_ctl.mode_ntpdate)
 			break;
 
 		start_kern_loop();
@@ -1241,7 +1243,7 @@ loop_config(
 	case LOOP_KERN_CLEAR:
 #if 0		/* XXX: needs more review, and how can we get here? */
 #ifndef ENABLE_LOCKCLOCK
-		if (pll_control && kern_enable) {
+		if (clock_ctl.pll_control && clock_ctl.kern_enable) {
 			memset((char *)&ntv, 0, sizeof(ntv));
 			ntv.modes = MOD_STATUS;
 			ntv.status = STA_UNSYNC;
@@ -1344,7 +1346,7 @@ pll_trap(
 	)
 {
 	UNUSED_ARG(arg);
-	pll_control = false;
+	clock_ctl.pll_control = false;
 	siglongjmp(env, 1);
 }
 #endif /* SIGSYS */


=====================================
ntpd/ntp_peer.c
=====================================
--- a/ntpd/ntp_peer.c
+++ b/ntpd/ntp_peer.c
@@ -664,7 +664,7 @@ newpeer(
 		peer_clear(peer, "BCST", initializing1);
 	else
 		peer_clear(peer, "INIT", initializing1);
-	if (mode_ntpdate)
+	if (clock_ctl.mode_ntpdate)
 		peer_ntpdate++;
 
 	/*


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -940,7 +940,7 @@ transmit(
 			 * set and all peers have completed the burst,
 			 * we declare a successful failure.
 			 */
-			if (mode_ntpdate) {
+			if (clock_ctl.mode_ntpdate) {
 				peer_ntpdate--;
 				if (peer_ntpdate == 0) {
 					msyslog(LOG_NOTICE,
@@ -2755,7 +2755,7 @@ init_proto(const bool verbose)
 	orphwait = current_time + (unsigned long)sys_orphwait;
 	proto_clr_stats();
 	stat_count.use_stattime = current_time;
-	hardpps_enable = false;
+	clock_ctl.hardpps_enable = false;
 	stats_control = true;
 }
 
@@ -2803,11 +2803,11 @@ proto_config(
 		break;
 
 	case PROTO_NTP:		/* NTP discipline (ntp) */
-		ntp_enable = (bool)value;
+		clock_ctl.ntp_enable = (bool)value;
 		break;
 
 	case PROTO_PPS:		/* PPS discipline (pps) */
-		hardpps_enable = (bool)value;
+		clock_ctl.hardpps_enable = (bool)value;
 		break;
 
 	case PROTO_FILEGEN:	/* statistics (stats) */


=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -991,7 +991,7 @@ refclock_params(
 				"REFCLOCK: refclock_params: time_pps_kcbind: %m");
 			return false;
 		}
-		hardpps_enable = true;
+		clock_ctl.hardpps_enable = true;
 	}
 	return true;
 }


=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -373,7 +373,7 @@ check_leapsec(
 
 	leap_result_t lsdata;
 	uint32_t       lsprox;
-	leapsec_electric((pll_control && kern_enable) ? electric_on : electric_off);
+	leapsec_electric((clock_ctl.pll_control && clock_ctl.kern_enable) ? electric_on : electric_off);
 #ifdef ENABLE_LEAP_SMEAR
 	leap_smear.enabled = (leap_smear_intv != 0);
 #endif


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -261,10 +261,10 @@ parse_cmdline_opts(
 			driftfile = ntp_optarg;
 		break;
 	    case 'g':
-		allow_panic = true;
+		clock_ctl.allow_panic = true;
 		break;
 	    case 'G':
-		force_step_once = true;
+		clock_ctl.force_step_once = true;
 		break;
 	    case 'h':
 		ntpd_usage();
@@ -316,7 +316,7 @@ parse_cmdline_opts(
 		}
 		break;
 	    case 'q':
-		mode_ntpdate = true;
+		clock_ctl.mode_ntpdate = true;
 		nofork = true;
 		break;
 	    case 'r':
@@ -835,9 +835,9 @@ ntpdmain(
 	    if (driftfile)
 		fprintf(stdout, "driftfile \"%s\";\n", driftfile);
 	    fprintf(stdout, "#allow_panic = %s\n",
-		    allow_panic ? "true" : "false");
+		    clock_ctl.allow_panic ? "true" : "false");
 	    fprintf(stdout, "#force_step_once = %s\n",
-		    force_step_once ? "true" : "false");
+		    clock_ctl.force_step_once ? "true" : "false");
 #ifdef ENABLE_DROPROOT
 	    if (chrootdir)
 		fprintf(stdout, "#chrootdir = \"%s\";\n", chrootdir);
@@ -860,7 +860,7 @@ ntpdmain(
 		fprintf(stdout, "pidfile \"%s\";\n", pidfile);
 	    /* FIXME: dump priority */
 	    fprintf(stdout, "#mode_ntpdate = %s\n",
-		    mode_ntpdate ? "true" : "false");
+		    clock_ctl.mode_ntpdate ? "true" : "false");
 	    if (statsdir[0])
 		fprintf(stdout, "statsdir \"%s\";\n", statsdir);
 	    fprintf(stdout, "#interface_interval = %d\n", interface_interval);


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -2402,7 +2402,7 @@ parse_hardpps(
 			 * tell the rest, that we have a kernel PPS source, iff we ever enable HARDPPS
 			 */
 			if (mode == PARSE_HARDPPS_ENABLE)
-			        hardpps_enable = true;
+			        clock_ctl.hardpps_enable = true;
 		}
 	}
 


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -908,7 +908,7 @@ oncore_ppsapi(
 			return false;
 		}
 
-		hardpps_enable = true;
+		clock_ctl.hardpps_enable = true;
 	}
 	return true;
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/c2eb57fdec36bd4d62bdf7b17997ea2789659c06

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/c2eb57fdec36bd4d62bdf7b17997ea2789659c06
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180520/eb79025e/attachment.html>


More information about the vc mailing list