From: Harlan Stenn Date: Fri, 24 Feb 2006 09:20:07 +0000 (-0500) Subject: Let there be fuzz. Make sure sys_precision is visible and present. X-Git-Tag: NTP_4_2_0B_RC1~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7e522626694da78d7f35e574a6010ba35bdf72f;p=thirdparty%2Fntp.git Let there be fuzz. Make sure sys_precision is visible and present. bk: 43fecfc7PWWbTr7Sg4km_-aIMSta3g --- diff --git a/libntp/systime.c b/libntp/systime.c index 4c7234a6e..4539b5fec 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -10,9 +10,10 @@ #include "ntp_unixtime.h" #include "ntp_stdlib.h" #include "ntp_random.h" +#include "ntpd.h" /* for sys_precision */ #ifdef SIM -#include "ntpsim.h" +# include "ntpsim.h" #endif /*SIM */ #ifdef HAVE_SYS_PARAM_H @@ -63,6 +64,7 @@ get_systime( /* * Convert Unix clock from seconds and nanoseconds to seconds. * The bottom is only two bits down, so no need for fuzz. + * Some systems don't have that level of precision, however... */ # ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &ts); @@ -83,8 +85,10 @@ get_systime( now->l_i = tv.tv_sec + JAN_1970; dtemp = tv.tv_usec / 1e6; +#endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ + /* - * ntp_random() produces 31 bits (always nonnegative. + * ntp_random() produces 31 bits (always nonnegative). * This bit is done only after the precision has been * determined. */ @@ -92,8 +96,6 @@ get_systime( dtemp += (ntp_random() / FRAC - .5) / (1 << -sys_precision); -#endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ - /* * Renormalize to seconds past 1900 and fraction. */ @@ -192,11 +194,11 @@ step_systime( (double)adjtv.tv_sec) * 1e6 + .5); } #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) -#ifdef HAVE_CLOCK_GETTIME +# ifdef HAVE_CLOCK_GETTIME (void) clock_gettime(CLOCK_REALTIME, &ts); -#else +# else (void) getclock(TIMEOFDAY, &ts); -#endif +# endif timetv.tv_sec = ts.tv_sec; timetv.tv_usec = ts.tv_nsec / 1000; #else /* not HAVE_GETCLOCK */ diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 96546644a..e1fe65eb9 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -115,6 +115,11 @@ static timer_t ntpdate_timerid; #define NTP_MAXLIST 5 /* maximum select list size */ #define PEER_SHIFT 8 /* 8 suitable for crystal time base */ +/* + * for get_systime() + */ +s_char sys_precision; /* local clock precision (log2 s) */ + /* * Debugging flag */ diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 4c73b001b..98a5d7daf 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -56,6 +56,11 @@ static u_long info_auth_keyid; static int info_auth_keytype = KEY_TYPE_MD5; /* MD5 */ u_long current_time; /* needed by authkeys; not used */ +/* + * for get_systime() + */ +s_char sys_precision; /* local clock precision (log2 s) */ + int ntpdcmain P((int, char **)); /* * Built in command handler declarations diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 6994e36a8..05b5bf50e 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -47,6 +47,11 @@ int interactive = 0; /* set to 1 when we should prompt */ const char *prompt = "ntpq> "; /* prompt to ask him about */ +/* + * for get_systime() + */ +s_char sys_precision; /* local clock precision (log2 s) */ + /* * Keyid used for authenticated requests. Obtained on the fly. */