]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2597] leap file loose ends
authorJuergen Perlinger <perlinger@ntp.org>
Wed, 16 Jul 2014 22:02:39 +0000 (00:02 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Wed, 16 Jul 2014 22:02:39 +0000 (00:02 +0200)
 - uniform log messages for timer and config triggered leap file loads
 - timer triggered load errors only once per day

bk: 53c6f67fYtzDYnufe7fwnyQxcGWZaw

ChangeLog
ntpd/ntp_leapsec.c
ntpd/ntp_leapsec.h
ntpd/ntp_timer.c
ntpd/ntp_util.c

index d4acbf040d715c8af28fb28719ca8a1886c53ec4..49808e7cfd5440ef2d7d387a579e72176925e39b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* [Bug 2597] leap file loose ends (follow-up)
+  - uniform expiration check messages for config and timer triggered
+    leap file loads
+  - timer triggered loads log messages only once per day
 (4.2.7p449) 2014/07/16 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 2547] Automate update of "Last Update" datestamps in .html files.
 * [Bug 2623] Missing {} in refclock_oncore.c.
index 136958d2353a18e0f8500cb26f674ef3adb49a8b..14b8cd99fa560644ff043b122c524c82532e756e 100644 (file)
@@ -375,7 +375,8 @@ leapsec_reset_frame(void)
 int/*BOOL*/
 leapsec_load_stream(
        FILE       * ifp  ,
-       const char * fname)
+       const char * fname,
+       int/*BOOL*/  logall)
 {
        leap_table_t *pt;
        int           rcheck;
@@ -384,30 +385,31 @@ leapsec_load_stream(
                fname = "<unknown>";
 
        rcheck = leapsec_validate((leapsec_reader)getc, ifp);
-       switch (rcheck)
-       {
-       case LSVALID_GOODHASH:
-               msyslog(LOG_NOTICE, "%s ('%s'): good hash signature",
-                       logPrefix, fname);
-               break;
-
-       case LSVALID_NOHASH:
-               msyslog(LOG_NOTICE, "%s ('%s'): no hash signature",
-                       logPrefix, fname);
-               break;
-       case LSVALID_BADHASH:
-               msyslog(LOG_ERR, "%s ('%s'): signature mismatch",
-                       logPrefix, fname);
-               break;
-       case LSVALID_BADFORMAT:
-               msyslog(LOG_ERR, "%s ('%s'): malformed hash signature",
-                       logPrefix, fname);
-               break;
-       default:
-               msyslog(LOG_ERR, "%s ('%s'): unknown error code %d",
-                       logPrefix, fname, rcheck);
-               break;
-       }
+       if (logall)
+               switch (rcheck)
+               {
+               case LSVALID_GOODHASH:
+                       msyslog(LOG_NOTICE, "%s ('%s'): good hash signature",
+                               logPrefix, fname);
+                       break;
+                       
+               case LSVALID_NOHASH:
+                       msyslog(LOG_ERR, "%s ('%s'): no hash signature",
+                               logPrefix, fname);
+                       break;
+               case LSVALID_BADHASH:
+                       msyslog(LOG_ERR, "%s ('%s'): signature mismatch",
+                               logPrefix, fname);
+                       break;
+               case LSVALID_BADFORMAT:
+                       msyslog(LOG_ERR, "%s ('%s'): malformed hash signature",
+                               logPrefix, fname);
+                       break;
+               default:
+                       msyslog(LOG_ERR, "%s ('%s'): unknown error code %d",
+                               logPrefix, fname, rcheck);
+                       break;
+               }
        if (rcheck < 0)
                return FALSE;
 
@@ -449,7 +451,8 @@ int/*BOOL*/
 leapsec_load_file(
        const char  * fname,
        struct stat * sb_old,
-       int/*BOOL*/   force)
+       int/*BOOL*/   force,
+       int/*BOOL*/   logall)
 {
        FILE       * fp;
        struct stat  sb_new;
@@ -461,8 +464,9 @@ leapsec_load_file(
        
        /* try to stat the leapfile */
        if (0 != stat(fname, &sb_new)) {
-               msyslog(LOG_ERR, "%s ('%s'): stat failed: %m",
-                       logPrefix, fname);
+               if (logall)
+                       msyslog(LOG_ERR, "%s ('%s'): stat failed: %m",
+                               logPrefix, fname);
                return FALSE;
        }
 
@@ -494,13 +498,14 @@ leapsec_load_file(
         */
        /* coverity[toctou] */
        if ((fp = fopen(fname, "r")) == NULL) {
-               msyslog(LOG_ERR,
-                       "%s ('%s'): open failed: %m",
-                       logPrefix, fname);
+               if (logall)
+                       msyslog(LOG_ERR,
+                               "%s ('%s'): open failed: %m",
+                               logPrefix, fname);
                return FALSE;
        }
 
-       rc = leapsec_load_stream(fp, fname);
+       rc = leapsec_load_stream(fp, fname, logall);
        fclose(fp);
        return rc;
 }
index 472790db856d1fa04c9cad8684f738caa8be53ab..75edcc4608f76c6b5a84d258ede1c1668f47f2b3 100644 (file)
@@ -134,7 +134,8 @@ extern void leapsec_dump(const leap_table_t*, leapsec_dumper func, void *farg);
 /* Read a leap second file from stream. This is a convenience wrapper
  * around the generic load function, 'leapsec_load()'.
  */
-extern int/*BOOL*/ leapsec_load_stream(FILE * fp, const char * fname);
+extern int/*BOOL*/ leapsec_load_stream(FILE * fp, const char * fname,
+                                      int/*BOOL*/logall);
 
 /* Read a leap second file from file. It checks that the file exists and
  * (if 'force' is not applied) the ctime/mtime has changed since the
@@ -144,7 +145,7 @@ extern int/*BOOL*/ leapsec_load_stream(FILE * fp, const char * fname);
  * otherwise. Uses 'leapsec_load_stream()' internally.
  */
 extern int/*BOOL*/ leapsec_load_file(const char * fname, struct stat * sb,
-                                    int/*BOOL*/force);
+                                    int/*BOOL*/force, int/*BOOL*/logall);
 
 /* Get the current leap data signature. This consists of the last
  * ransition, the table expiration, and the total TAI difference at the
index b51aa37d174a4c9e98b968ab2f66cd1706fd9a98..958c8db394003e32c822a4d8c9ef9dbb18ac0214 100644 (file)
@@ -66,7 +66,7 @@ volatile int alarm_flag;
 static  u_long interface_timer;        /* interface update timer */
 static u_long adjust_timer;    /* second timer */
 static u_long stats_timer;     /* stats timer */
-static u_long check_leapfile;  /* Report leapfile problems once/day */
+static u_long leapf_timer;     /* Report leapfile problems once/day */
 static u_long huffpuff_timer;  /* huff-n'-puff timer */
 static u_long worker_idle_timer;/* next check for idle intres */
 u_long leapsec;                /* seconds to next leap (proximity class) */
@@ -189,7 +189,7 @@ init_timer(void)
        alarm_overflow = 0;
        adjust_timer = 1;
        stats_timer = SECSPERHR;
-       check_leapfile = 0;
+       leapf_timer = SECSPERDAY;
        huffpuff_timer = 0;
        interface_timer = 0;
        current_time = 0;
@@ -425,8 +425,8 @@ timer(void)
        if (stats_timer <= current_time) {
                stats_timer += SECSPERHR;
                write_stats();
-               if (check_leapfile < current_time) {
-                       check_leapfile += SECSPERDAY;
+               if (leapf_timer <= current_time) {
+                       leapf_timer += SECSPERDAY;
                        check_leap_file(TRUE, now.l_ui, &tnow);
                } else {
                        check_leap_file(FALSE, now.l_ui, &tnow);
index 145b0b3008875e2fa1a09e1eed37428038cf964f..a7da52b86141c8a9006357e27faac2f2ca24b095 100644 (file)
@@ -101,6 +101,7 @@ static double prev_drift_comp;              /* last frequency update */
  */
 static void    record_sys_stats(void);
        void    ntpd_time_stepped(void);
+static  void   check_leap_expiration(int, uint32_t, const time_t*);
 
 /* 
  * Prototypes
@@ -109,7 +110,6 @@ static      void    record_sys_stats(void);
 void   uninit_util(void);
 #endif
 
-
 /*
  * uninit_util - free memory allocated by init_util
  */
@@ -337,6 +337,7 @@ stats_config(
        int     len;
        double  old_drift;
        l_fp    now;
+       time_t  ttnow;
 #ifndef VMS
        const char temp_ext[] = ".TEMP";
 #else
@@ -483,11 +484,14 @@ stats_config(
                leapfile_name = erealloc(leapfile_name, len + 1);
                memcpy(leapfile_name, value, len + 1);
 
-               if (leapsec_load_file(leapfile_name, &leapfile_stat, TRUE)) {
+               if (leapsec_load_file(
+                           leapfile_name, &leapfile_stat, TRUE, TRUE))
+               {
                        leap_signature_t lsig;
 
-                       leapsec_getsig(&lsig);
                        get_systime(&now);
+                       time(&ttnow);
+                       leapsec_getsig(&lsig);
                        mprintf_event(EVNT_TAI, NULL,
                                      "%d leap %s %s %s",
                                      lsig.taiof,
@@ -496,7 +500,13 @@ stats_config(
                                          ? "expired"
                                          : "expires",
                                      fstostr(lsig.etime));
+
                        have_leapfile = TRUE;
+
+                       /* force an immediate daily expiration check of
+                        * the leap seconds table
+                        */
+                       check_leap_expiration(TRUE, now.l_ui, &ttnow);
                }
                break;
 
@@ -852,10 +862,7 @@ 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 or less than 24hrs remaining TTL
- *     >0 # of full days until the leapfile expires
+ * Returns: n/a
  *
  * Note: This loads a new leapfile on the fly. Currently a leap file
  * without SHA1 signature is accepted, but if there is a signature line,
@@ -868,20 +875,34 @@ check_leap_file(
        const time_t *systime
        )
 {
-       static const char * const logPrefix = "leapsecond file";
-       int  rc;
-
        /* just do nothing if there is no leap file */
        if ( ! (leapfile_name && *leapfile_name))
                return;
        
        /* try to load leapfile, force it if no leapfile loaded yet */
        if (leapsec_load_file(
-                   leapfile_name, &leapfile_stat, !have_leapfile))
+                   leapfile_name, &leapfile_stat,
+                   !have_leapfile, is_daily_check))
                have_leapfile = TRUE;
        else if (!have_leapfile)
                return;
 
+       check_leap_expiration(is_daily_check, ntptime, systime);
+}
+
+/*
+ * check expiration of a loaded leap table
+ */
+static void
+check_leap_expiration(
+       int           is_daily_check,
+       uint32_t      ntptime       ,
+       const time_t *systime
+       )
+{
+       static const char * const logPrefix = "leapsecond file";
+       int  rc;
+
        /* test the expiration of the leap data and log with proper
         * level and frequency (once/hour or once/day, depending on the
         * state.