[Git][NTPsec/ntpsec][master] Change prettydate() to always emit UTC, for reproducibility.
Eric S. Raymond
gitlab at mg.gitlab.com
Sat Sep 9 16:13:07 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
e0ba7d32 by Eric S. Raymond at 2017-09-09T12:12:39-04:00
Change prettydate() to always emit UTC, for reproducibility.
This means we can get rid of gmprettydate().
- - - - -
5 changed files:
- include/ntp_fp.h
- libntp/prettydate.c
- ntpd/refclock_generic.c
- ntpd/refclock_gpsd.c
- tests/libntp/prettydate.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -161,7 +161,6 @@ extern char * mfptoms (l_fp, short);
extern bool hextolfp (const char *, l_fp *);
extern char * prettydate (const l_fp);
-extern char * gmprettydate (const l_fp);
extern char * rfc3339date (const l_fp);
extern char * rfc3339time (time_t);
=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -14,8 +14,6 @@
# error sizeof(time_t) < 4 -- this will not work!
#endif
-static char *common_prettydate(const l_fp, bool);
-
/* Helper function to handle possible wraparound of the ntp epoch.
*
* Works by periodic extension of the ntp time stamp in the UN*X epoch.
@@ -52,7 +50,6 @@ static char *common_prettydate(const l_fp, bool);
static struct tm *
get_struct_tm(
const time64_t *stamp,
- int local,
struct tm *tmbuf)
{
struct tm *tm;
@@ -91,8 +88,11 @@ get_struct_tm(
* At least the MSDN says that the (Microsoft) Windoze
* versions of 'gmtime_r()' and 'localtime_r()' will bark on time
* stamps < 0.
+ *
+ * ESR, 2017: Using localtime(3) for logging at all is bogus -
+ * in particular bad for reproducibility.
*/
- while ((tm = (*(local ? localtime_r : gmtime_r))(&ts, tmbuf)) == NULL)
+ while ((tm = gmtime_r(&ts, tmbuf)) == NULL)
if (ts < 0) {
if (--folds < MINFOLD)
return NULL;
@@ -116,8 +116,7 @@ get_struct_tm(
static char *
common_prettydate(
- const l_fp ts,
- bool local
+ const l_fp ts
)
{
static const char pfmt[] =
@@ -139,7 +138,7 @@ common_prettydate(
ntps++;
}
sec = ntpcal_ntp_to_time(ntps, NULL);
- tm = get_struct_tm(&sec, local, &tmbuf);
+ tm = get_struct_tm(&sec, &tmbuf);
if (!tm) {
/*
* get a replacement, but always in UTC, using
@@ -157,8 +156,7 @@ common_prettydate(
(unsigned long)lfpuint(ts), (unsigned long)lfpfrac(ts),
1900 + tm->tm_year, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, msec);
- if (!local)
- strncat(bp, "Z", LIB_BUFLENGTH);
+ strncat(bp, "Z", LIB_BUFLENGTH);
}
return bp;
}
@@ -169,7 +167,7 @@ prettydate(
const l_fp ts
)
{
- return common_prettydate(ts, true);
+ return common_prettydate(ts);
}
@@ -178,18 +176,10 @@ rfc3339date(
const l_fp ts
)
{
- return common_prettydate(ts, false) + 18; /* skip past hex time */
+ return common_prettydate(ts) + 18; /* skip past hex time */
}
-char *
-gmprettydate(
- const l_fp ts
- )
-{
- return common_prettydate(ts, false);
-}
-
/*
* rfc3339time - prettyprint time stamp - POSIX epoch
*/
=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -3056,7 +3056,7 @@ parse_control(
if (PARSE_PPS(parse->timedata.parse_state))
{
tt = add_var(&out->kv_list, 80, RO|DEF);
- snprintf(tt, 80, "refclock_ppstime=\"%s\"", gmprettydate(parse->timedata.parse_ptime));
+ snprintf(tt, 80, "refclock_ppstime=\"%s\"", prettydate(parse->timedata.parse_ptime));
}
start = tt = add_var(&out->kv_list, 128, RO|DEF);
@@ -3069,7 +3069,7 @@ parse_control(
else
{
ap(start, 128, tt, "%s\"",
- gmprettydate(parse->timedata.parse_time));
+ prettydate(parse->timedata.parse_time));
}
if (!PARSE_GETTIMECODE(parse, &tmpctl))
=====================================
ntpd/refclock_gpsd.c
=====================================
--- a/ntpd/refclock_gpsd.c
+++ b/ntpd/refclock_gpsd.c
@@ -1544,8 +1544,8 @@ process_tpv(
DPRINT(2, ("%s: process_tpv, stamp='%s',"
" recvt='%s' mode=%d\n",
up->logname,
- gmprettydate(up->ibt_stamp),
- gmprettydate(up->ibt_recvt),
+ prettydate(up->ibt_stamp),
+ prettydate(up->ibt_recvt),
gps_mode));
/* have to use local receive time as substitute
@@ -1641,12 +1641,12 @@ process_pps(
setlfpfrac(up->pps_stamp, 0);
if (NULL != up->pps_peer)
- save_ltc(up->pps_peer->procptr, gmprettydate(up->pps_stamp2));
+ save_ltc(up->pps_peer->procptr, prettydate(up->pps_stamp2));
DPRINT(2, ("%s: PPS record processed,"
" stamp='%s', recvt='%s'\n",
up->logname,
- gmprettydate(up->pps_stamp2),
- gmprettydate(up->pps_recvt2)));
+ prettydate(up->pps_stamp2),
+ prettydate(up->pps_recvt2)));
up->fl_pps = (0 != (pp->sloppyclockflag & CLK_FLAG2)) - 1;
up->fl_pps2 = -1;
@@ -1688,12 +1688,12 @@ process_toff(
up->ibt_local = *rtime;
up->fl_ibt = -1;
- save_ltc(pp, gmprettydate(up->ibt_stamp));
+ save_ltc(pp, prettydate(up->ibt_stamp));
DPRINT(2, ("%s: TOFF record processed,"
" stamp='%s', recvt='%s'\n",
up->logname,
- gmprettydate(up->ibt_stamp),
- gmprettydate(up->ibt_recvt)));
+ prettydate(up->ibt_stamp),
+ prettydate(up->ibt_recvt)));
return;
fail:
=====================================
tests/libntp/prettydate.c
=====================================
--- a/tests/libntp/prettydate.c
+++ b/tests/libntp/prettydate.c
@@ -18,7 +18,7 @@ static const uint32_t HALF = 2147483648UL;
TEST(prettydate, ConstantDate) {
l_fp t = lfpinit((int32_t)3485080800LL, HALF); // 2010-06-09 14:00:00.5
- TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(t));
+ TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", prettydate(t));
}
TEST_GROUP_RUNNER(prettydate) {
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/e0ba7d32c638861d7827b36a010c06752e895e90
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/e0ba7d32c638861d7827b36a010c06752e895e90
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/20170909/156c90d5/attachment.html>
More information about the vc
mailing list