]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2326] Improve stale leapsecond notifications
authorHarlan Stenn <stenn@ntp.org>
Sun, 17 Nov 2013 09:03:39 +0000 (09:03 +0000)
committerHarlan Stenn <stenn@ntp.org>
Sun, 17 Nov 2013 09:03:39 +0000 (09:03 +0000)
bk: 5288866b3sp1siiglKZk1y6dGGPuEg

ChangeLog
include/ntpd.h
ntpd/ntp_io.c
ntpd/ntp_timer.c
ntpd/ntp_util.c

index e1d4267a28e06bf3e39efd51d989956e1656ec1a..1c73df49be48dc9e854e2b0d7a20878b7151067c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [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>
index d6f259c611cc79a23266752bd2961b9a89738f64..52a0433aaf27ba0545dfc03fb87d0b710d055933 100644 (file)
@@ -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 *);
index c5701d294a5ebd17b54e86da8edff39a687cbab2..4ec67c8d87b6cc5dd1cd7936e3c2809e8ea95017 100644 (file)
@@ -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;
 }
index 2c0780452124c443682ded2462f693b20e70aa9b..35562bc37ac54ca7c596515088e831892950a52f 100644 (file)
@@ -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;
        }
index a3e4f58e9316efff5cbcd32c7ce2d7d7442a9b28..9f538c1de9611d91819d6cab1df33d3977e6e428 100644 (file)
@@ -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;
 }