[Git][NTPsec/ntpsec][master] Merge two duplicative date-reporting functions; use RFC3339 format.
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Mar 15 16:34:18 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
0a56f7f6 by Eric S. Raymond at 2017-03-15T12:33:19-04:00
Merge two duplicative date-reporting functions; use RFC3339 format.
- - - - -
5 changed files:
- include/ntp_fp.h
- include/ntpd.h
- libntp/prettydate.c
- ntpd/ntp_leapsec.c
- ntpd/ntp_util.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -193,6 +193,7 @@ extern bool mstolfp (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);
extern void set_sys_fuzz (double);
extern void get_ostime (struct timespec *tsp);
=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -234,7 +234,6 @@ extern void record_crypto_stats (sockaddr_u *, const char *);
#ifdef DEBUG
extern void record_timing_stats (const char *);
#endif
-extern char * rfc3339time(time_t);
/* packetstamp.c */
extern void enable_packetstamps(int, sockaddr_u *);
=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -190,3 +190,29 @@ gmprettydate(
return common_prettydate(ts, false);
}
+/*
+ * rfc3339time - prettyprint time stamp - POSIX epoch
+ */
+char * rfc3339time(
+ time_t posix_stamp
+ )
+{
+ char * buf;
+ struct tm tm, *tm2;
+
+ LIB_GETBUF(buf);
+ tm2 = gmtime_r(&posix_stamp, &tm);
+ if (tm2 == NULL || tm.tm_year > 9999)
+ snprintf(buf, LIB_BUFLENGTH, "rfc3339time: %ld: range error",
+ (long)posix_stamp);
+ // if (ntpcal_ntp_to_date(&tm, (uint32_t)ntp_stamp, NULL) < 0)
+ // snprintf(buf, LIB_BUFLENGTH, "ntpcal_ntp_to_date: %ld: range error",
+ // (long)ntp_stamp);
+ else
+ snprintf(buf, LIB_BUFLENGTH, "%04d-%02d-%02dT%02d:%02dZ",
+ tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min);
+ return buf;
+}
+
+/* end */
=====================================
ntpd/ntp_leapsec.c
=====================================
--- a/ntpd/ntp_leapsec.c
+++ b/ntpd/ntp_leapsec.c
@@ -26,6 +26,7 @@
#include "ntp_calendar.h"
#include "ntp_leapsec.h"
#include "ntp.h"
+#include "ntpd.h" /* for rfc3339time() only */
#include "lib_strbuf.h"
#include <openssl/evp.h>
@@ -81,7 +82,6 @@ static void reload_limits(leap_table_t*, time_t);
static void reset_times(leap_table_t*);
static bool leapsec_add(leap_table_t*, time_t, int);
static bool leapsec_raw(leap_table_t*, time_t, int, bool);
-static char * lstostr(time_t ts);
/* time_t is unsigned. This is used for infinity in tables */
#if NTP_SIZEOF_TIME_T == 8
@@ -431,12 +431,12 @@ leapsec_load_stream(
if (pt->head.size)
msyslog(LOG_NOTICE, "%s ('%s'): loaded, expire=%s last=%s ofs=%d",
- logPrefix, fname, lstostr(pt->head.expire),
- lstostr(pt->info[0].ttime), pt->info[0].taiof);
+ logPrefix, fname, rfc3339time(pt->head.expire),
+ rfc3339time(pt->info[0].ttime), pt->info[0].taiof);
else
msyslog(LOG_NOTICE,
"%s ('%s'): loaded, expire=%s ofs=%d (no entries after build date)",
- logPrefix, fname, lstostr(pt->head.expire),
+ logPrefix, fname, rfc3339time(pt->head.expire),
pt->head.base_tai);
return leapsec_set_table(pt);
@@ -952,23 +952,6 @@ leapsec_validate(
return LSVALID_GOODHASH;
}
-/*
- * lstostr - prettyprint POSIX seconds
- */
-static char * lstostr(
- const time_t ts)
-{
- char * buf;
- struct tm tm;
-
- LIB_GETBUF(buf);
- gmtime_r(&ts, &tm);
- snprintf(buf, LIB_BUFLENGTH, "%04d-%02d-%02dT%02d:%02dZ",
- tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
- tm.tm_hour, tm.tm_min);
- return buf;
-}
-
/* reset the global state for unit tests */
void
leapsec_ut_pristine(void)
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -820,32 +820,6 @@ ntp_exit(int retval)
#endif
/*
- * rfc3339time - prettyprint time stamp - POSIX epoch
- */
-char * rfc3339time(
- time_t posix_stamp
- )
-{
- char * buf;
- struct tm tm, *tm2;
-
- LIB_GETBUF(buf);
- tm2 = gmtime_r(&posix_stamp, &tm);
- if (tm2 == NULL || tm.tm_year > 9999)
- snprintf(buf, LIB_BUFLENGTH, "rfc3339time: %ld: range error",
- (long)posix_stamp);
- // if (ntpcal_ntp_to_date(&tm, (uint32_t)ntp_stamp, NULL) < 0)
- // snprintf(buf, LIB_BUFLENGTH, "ntpcal_ntp_to_date: %ld: range error",
- // (long)ntp_stamp);
- else
- snprintf(buf, LIB_BUFLENGTH, "%04d-%02d-%02dT%02d:%02dZ",
- tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
- tm.tm_hour, tm.tm_min);
- return buf;
-}
-
-
-/*
* ntpd_time_stepped is called back by step_systime(), allowing ntpd
* to do any one-time processing necessitated by the step.
*/
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/0a56f7f612da3a4c9ec80704a9aa72eee1af3b80
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170315/c59259a3/attachment.html>
More information about the vc
mailing list