From: Harlan Stenn Date: Sun, 17 Nov 2013 09:03:39 +0000 (+0000) Subject: [Bug 2326] Improve stale leapsecond notifications X-Git-Tag: NTP_4_2_7P396~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70714917514668a01f1440f474d529a9761694cd;p=thirdparty%2Fntp.git [Bug 2326] Improve stale leapsecond notifications bk: 5288866b3sp1siiglKZk1y6dGGPuEg --- diff --git a/ChangeLog b/ChangeLog index e1d4267a2..1c73df49b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 2326] Improve stale leapsecond notifications. (4.2.7p395) 2013/11/12 Released by Harlan Stenn * Upgrade to autogen-5.18.3pre5 and libopts-40.1.15. (4.2.7p394) 2013/11/05 Released by Harlan Stenn diff --git a/include/ntpd.h b/include/ntpd.h index d6f259c61..52a0433aa 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -286,7 +286,7 @@ extern void record_clock_stats (sockaddr_u *, const char *); 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 *); diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index c5701d294..4ec67c8d8 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -3739,7 +3739,7 @@ input_handler( ih_return: if (check_leapfile < time(NULL)) { check_leapfile += CHECK_LEAP_EVERY; - check_leap_file(); + (void)check_leap_file(); } return; } diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 2c0780452..35562bc37 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -423,19 +423,27 @@ timer(void) 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; } diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index a3e4f58e9..9f538c1de 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -861,8 +861,13 @@ record_timing_stats( /* * 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 ) @@ -870,20 +875,21 @@ check_leap_file( 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)) { @@ -892,12 +898,17 @@ check_leap_file( 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; }