+* [Bug 2326] Improve stale leapsecond notifications.
(4.2.7p395) 2013/11/12 Released by Harlan Stenn <stenn@ntp.org>
* Upgrade to autogen-5.18.3pre5 and libopts-40.1.15.
(4.2.7p394) 2013/11/05 Released by Harlan Stenn <stenn@ntp.org>
extern int mprintf_clock_stats(sockaddr_u *, const char *, ...)
NTP_PRINTF(2, 3);
extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int poll, int precision, double root_delay, double root_dispersion, u_int32 refid);
-extern void check_leap_file (void);
+extern int check_leap_file (void);
extern void record_crypto_stats (sockaddr_u *, const char *);
#ifdef DEBUG
extern void record_timing_stats (const char *);
ih_return:
if (check_leapfile < time(NULL)) {
check_leapfile += CHECK_LEAP_EVERY;
- check_leap_file();
+ (void)check_leap_file();
}
return;
}
stats_timer += HOUR;
write_stats();
if (sys_tai != 0 && leapsec_expired(now.l_ui, &tnow)) {
- report_event(EVNT_LEAPVAL, NULL, NULL);
- if (leap_warn_log == FALSE) {
+ int clf = check_leap_file();
+
+ /*
+ ** check_leap_file() returns -1 on a problem,
+ ** 0 on an expired leapsecond file, or the number
+ ** of days until the leapsecond file expires.
+ */
+ if (-1 == clf) {
+ /* nothing to do */
+ } else if (0 == clf) {
+ report_event(EVNT_LEAPVAL, NULL, NULL);
+ if (leap_warn_log == FALSE) {
+ msyslog(LOG_WARNING,
+ "leapseconds data file has expire!.");
+ leap_warn_log = TRUE;
+ }
+ } else if (clf < 31) {
msyslog(LOG_WARNING,
- "leapseconds data file has expired.");
- leap_warn_log = TRUE;
+ "leapseconds data file will expire in about %d days' time!", clf);
+ /* squawk that leapfile will expire */
}
- /* If a new file was installed between
- * the previous 24 hour check and the
- * expiration of this one, we'll squawk
- * once. Better than checking for a
- * new file every hour...
- */
- check_leap_file();
} else
leap_warn_log = FALSE;
}
/*
* check_leap_file - See if the leapseconds file has been updated.
+ *
+ * Returns:
+ * -1 if there was a problem,
+ * 0 if the leapfile has expired
+ * >0 # of days until the leapfile expires
*/
-void
+int
check_leap_file(
void
)
FILE *fp;
struct stat *sp1 = &leapseconds_file_sb1;
struct stat *sp2 = &leapseconds_file_sb2;
+ int rc;
if (leapseconds_file) {
if ((fp = fopen(leapseconds_file, "r")) == NULL) {
msyslog(LOG_ERR,
"check_leap_file: fopen(%s): %m",
leapseconds_file);
- return;
+ return -1;
}
if (fstat(fileno(fp), &leapseconds_file_sb2)) {
msyslog(LOG_ERR,
"check_leap_file: stat(%s): %m",
leapseconds_file);
fclose(fp);
- return;
+ return -1;
}
if ( (sp1->st_mtime != sp2->st_mtime)
|| (sp1->st_ctime != sp2->st_ctime)) {
msyslog(LOG_ERR,
"format error leapseconds file %s",
leapseconds_file);
+ rc = -1;
+ } else {
+ rc = 1; /* XXX: 0 or days til expire */
}
+ } else {
+ rc = 0; /* XXX: 0 or days til expire */
}
fclose(fp);
}
- return;
+ return rc;
}