[Git][NTPsec/ntpsec][master] Small refactoring step - hide STA_NANO conditionalization.
Eric S. Raymond
gitlab at mg.gitlab.com
Tue Oct 11 20:21:09 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
838227e1 by Eric S. Raymond at 2016-10-11T16:20:05-04:00
Small refactoring step - hide STA_NANO conditionalization.
- - - - -
2 changed files:
- include/ntp_syscall.h
- ntpd/ntp_control.c
Changes:
=====================================
include/ntp_syscall.h
=====================================
--- a/include/ntp_syscall.h
+++ b/include/ntp_syscall.h
@@ -27,6 +27,20 @@ struct ntptimeval
int ntp_gettime(struct ntptimeval *);
#endif /* !HAVE_STRUCT_NTPTIMEVAL */
+/*
+ * The units of the maxerror and esterror fields vary by platform. If
+ * STA_NANO is defined, they're in nanoseconds;, otherwise in
+ * microseconds. Hide the difference by normalizing everything to
+ * float seconds.
+ */
+# ifdef STA_NANO
+#define ntp_error_in_seconds(n) ((n)/1.0e9)
+# else
+#define ntp_error_in_seconds(n) ((n)/1.0e6)
+# endif
+
+
+
/* MUSL port shim */
#if !defined(HAVE_NTP_ADJTIME) && defined(HAVE_ADJTIMEX)
#define ntp_adjtime adjtimex
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -644,6 +644,8 @@ static char *reqend;
#define MIN(a, b) (((a) <= (b)) ? (a) : (b))
#endif
+#define MILLISECONDS 1000 /* milliseconds per second -magic numbers suck */
+
/*
* init_control - initialize request data
*/
@@ -1407,13 +1409,6 @@ ctl_putsys(
static struct timex ntx;
static u_long ntp_adjtime_time;
- static const double to_ms =
-# ifdef STA_NANO
- 1.0e-6; /* nsec to msec */
-# else
- 1.0e-3; /* usec to msec */
-# endif
-
/*
* CS_K_* variables depend on up-to-date output of ntp_adjtime()
*/
@@ -1800,7 +1795,8 @@ ctl_putsys(
case CS_K_OFFSET:
CTL_IF_KERNLOOP(
ctl_putdblf,
- (sys_var[varid].text, 0, -1, to_ms * ntx.offset)
+ (sys_var[varid].text, 0, -1,
+ ntp_error_in_seconds(ntx.offset)*MILLISECONDS)
);
break;
@@ -1815,7 +1811,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- to_ms * ntx.maxerror)
+ ntp_error_in_seconds(ntx.maxerror)*MILLISECONDS)
);
break;
@@ -1823,7 +1819,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- to_ms * ntx.esterror)
+ ntp_error_in_seconds(ntx.esterror)*MILLISECONDS)
);
break;
@@ -1847,7 +1843,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- to_ms * ntx.precision)
+ ntp_error_in_seconds(ntx.precision)*MILLISECONDS)
);
break;
@@ -1875,7 +1871,8 @@ ctl_putsys(
case CS_K_PPS_JITTER:
CTL_IF_KERNPPS(
ctl_putdbl,
- (sys_var[varid].text, to_ms * ntx.jitter)
+ (sys_var[varid].text,
+ ntp_error_in_seconds(ntx.jitter)*MILLISECONDS)
);
break;
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/838227e1abf76a98fcdec8721b27c9be7991134c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161011/50246875/attachment.html>
More information about the vc
mailing list