From: Harlan Stenn Date: Thu, 28 Nov 2013 05:20:43 +0000 (-0500) Subject: [Bug 2514] secs/* #define usage cleanup X-Git-Tag: NTP_4_2_7P399~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=288bac02f386899b8e8aaa42c182dd9da55ee85d;p=thirdparty%2Fntp.git [Bug 2514] secs/* #define usage cleanup bk: 5296d2abYvTNE-jaqjrVaGSBBYC8sQ --- diff --git a/ChangeLog b/ChangeLog index ff3343aa7..831d4d32f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ * [Bug 2326] More leapsecond file notification cleanup. +* [Bug 2514] secs/* #define usage cleanup. (4.2.7p398) 2013/11/25 Released by Harlan Stenn * [Bug 2326] More leapsecond file notification cleanup. * Improve sntp KoD data file fopen() error message. diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index c0e9aad7b..7c884fc32 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -59,10 +59,6 @@ extern void errno_to_str(int, char *, size_t); errno = preserved_errno; \ } -#define MINUTE 60 -#define HOUR (60 * MINUTE) -#define DAY (24 * HOUR) - typedef void (*ctrl_c_fn)(void); /* authkeys.c */ diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index a6d9b3d39..560da0aab 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -39,8 +39,6 @@ #define CLOCK_FLL .25 /* FLL loop gain */ #define CLOCK_FLOOR .0005 /* startup offset floor (s) */ #define CLOCK_ALLAN 11 /* Allan intercept (log2 s) */ -#define CLOCK_DAY 86400. /* one day in seconds (s) */ -#define CLOCK_JUNE (CLOCK_DAY * 30) /* June in seconds (s) */ #define CLOCK_LIMIT 30 /* poll-adjust threshold */ #define CLOCK_PGATE 4. /* poll-adjust gate */ #define PPS_MAXAGE 120 /* kernel pps signal timeout (s) */ diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 0d0fbbafc..74cde9e82 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -8,6 +8,7 @@ #include "ntp_machine.h" #include "ntpd.h" #include "ntp_stdlib.h" +#include "ntp_calendar.h" #include "ntp_leapsec.h" #if defined(HAVE_IO_COMPLETION_PORT) @@ -189,7 +190,7 @@ init_timer(void) alarm_flag = FALSE; alarm_overflow = 0; adjust_timer = 1; - stats_timer = HOUR; + stats_timer = SECSPERHR; check_leapfile = 0; huffpuff_timer = 0; interface_timer = 0; @@ -424,7 +425,7 @@ timer(void) * and daily leapfile checks. */ if (stats_timer <= current_time) { - stats_timer += HOUR; + stats_timer += SECSPERHR; write_stats(); if (sys_tai != 0 && leapsec_expired(now.l_ui, &tnow)) { int clf = check_leap_file(); @@ -437,7 +438,7 @@ timer(void) ** We only want to log stuff once/day. */ if (check_leapfile < current_time) { - check_leapfile += DAY; + check_leapfile += SECSPERDAY; if (-1 == clf) { /* nothing to do */ } else if (0 == clf) { diff --git a/ntpd/refclock_tsyncpci.c b/ntpd/refclock_tsyncpci.c index 125fcd20d..e70a7cf9c 100644 --- a/ntpd/refclock_tsyncpci.c +++ b/ntpd/refclock_tsyncpci.c @@ -102,16 +102,6 @@ // These define the base date/time of the system clock. The system time will // be tracked as the number of seconds from this date/time. #define TSYNC_TIME_BASE_YEAR (1970) // earliest acceptable year -#define TSYNC_SECS_PER_MIN (60) -#define TSYNC_MINS_PER_HR (60) -#define TSYNC_HRS_PER_DAY (24) -#define TSYNC_DAYS_PER_YR (365) -#define TSYNC_DAYS_PER_LYR (366) -#define TSYNC_SECS_PER_HR (TSYNC_MINS_PER_HR * TSYNC_SECS_PER_MIN) -#define TSYNC_SECS_PER_DAY (TSYNC_HRS_PER_DAY * TSYNC_SECS_PER_HR) -#define TSYNC_SECS_PER_YR (TSYNC_DAYS_PER_YR * TSYNC_SECS_PER_DAY) -#define TSYNC_SECS_PER_LYR (TSYNC_DAYS_PER_LYR * TSYNC_SECS_PER_DAY) - #define TSYNC_LCL_STRATUM (0) @@ -828,13 +818,13 @@ void SecTimeFromDoyTime(SecTimeObj* pSt, DoyTimeObj* pDt) lyrs = (yrs + 1) / 4; // Convert leap years and years - pSt->seconds += lyrs * TSYNC_SECS_PER_LYR; - pSt->seconds += (yrs - lyrs) * TSYNC_SECS_PER_YR; + pSt->seconds += lyrs * SECSPERLEAPYEAR; + pSt->seconds += (yrs - lyrs) * SECSPERYEAR; // Convert days, hours, minutes and seconds - pSt->seconds += (pDt->doy - 1) * TSYNC_SECS_PER_DAY; - pSt->seconds += pDt->hour * TSYNC_SECS_PER_HR; - pSt->seconds += pDt->minute * TSYNC_SECS_PER_MIN; + pSt->seconds += (pDt->doy - 1) * SECSPERDAY; + pSt->seconds += pDt->hour * SECSPERHR; + pSt->seconds += pDt->minute * SECSPERMIN; pSt->seconds += pDt->second; // Copy the subseconds count @@ -867,45 +857,45 @@ void DoyTimeFromSecTime(DoyTimeObj* pDt, SecTimeObj* pSt) // Calculate the number of 4 year chunks yrs = (unsigned int)((secs / - ((TSYNC_SECS_PER_YR * 3) + TSYNC_SECS_PER_LYR)) * 4); - secs %= ((TSYNC_SECS_PER_YR * 3) + TSYNC_SECS_PER_LYR); + ((SECSPERYEAR * 3) + SECSPERLEAPYEAR)) * 4); + secs %= ((SECSPERYEAR * 3) + SECSPERLEAPYEAR); // If there is at least a normal year worth of time left - if (secs >= TSYNC_SECS_PER_YR) + if (secs >= SECSPERYEAR) { // Increment the number of years and subtract a normal year of time yrs++; - secs -= TSYNC_SECS_PER_YR; + secs -= SECSPERYEAR; } // If there is still at least a normal year worth of time left - if (secs >= TSYNC_SECS_PER_YR) + if (secs >= SECSPERYEAR) { // Increment the number of years and subtract a normal year of time yrs++; - secs -= TSYNC_SECS_PER_YR; + secs -= SECSPERYEAR; } // If there is still at least a leap year worth of time left - if (secs >= TSYNC_SECS_PER_LYR) + if (secs >= SECSPERLEAPYEAR) { // Increment the number of years and subtract a leap year of time yrs++; - secs -= TSYNC_SECS_PER_LYR; + secs -= SECSPERLEAPYEAR; } // Calculate the day of year as the number of days left, then add 1 // because months start on the 1st. - doys = (unsigned int)((secs / TSYNC_SECS_PER_DAY) + 1); - secs %= TSYNC_SECS_PER_DAY; + doys = (unsigned int)((secs / SECSPERDAY) + 1); + secs %= SECSPERDAY; // Calculate the hour - hrs = (unsigned int)(secs / TSYNC_SECS_PER_HR); - secs %= TSYNC_SECS_PER_HR; + hrs = (unsigned int)(secs / SECSPERHR); + secs %= SECSPERHR; // Calculate the minute - mins = (unsigned int)(secs / TSYNC_SECS_PER_MIN); - secs %= TSYNC_SECS_PER_MIN; + mins = (unsigned int)(secs / SECSPERMIN); + secs %= SECSPERMIN; // Fill in the doytime structure pDt->year = yrs + TSYNC_TIME_BASE_YEAR; diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index cc15ab296..88e1f4b03 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -113,7 +113,6 @@ */ #define MD5KEYS 10 /* number of keys generated of each type */ #define MD5SIZE 20 /* maximum key size */ -#define YEAR ((long)365) /* one year in days */ #ifdef AUTOKEY #define PLEN 512 /* default prime modulus size (bits) */ #define ILEN 256 /* default identity modulus size (bits) */ @@ -155,7 +154,7 @@ u_long asn2ntp (ASN1_TIME *); */ extern char *optarg; /* command line argument */ char *progname; -u_int lifetime = YEAR; /* certificate lifetime (days) */ +u_int lifetime = DAYSPERYEAR; /* certificate lifetime (days) */ int nkeys; /* MV keys */ time_t epoch; /* Unix epoch (seconds) since 1970 */ u_int fstamp; /* NTP filestamp */ @@ -1946,7 +1945,7 @@ x509 ( X509_set_serialNumber(cert, serial); ASN1_INTEGER_free(serial); X509_time_adj(X509_get_notBefore(cert), 0L, &epoch); - X509_time_adj(X509_get_notAfter(cert), lifetime * DAY, &epoch); + X509_time_adj(X509_get_notAfter(cert), lifetime * SECSPERDAY, &epoch); subj = X509_get_subject_name(cert); X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC, (u_char *)name, strlen(name), -1, 0);