Use fixed-size fields in the structure for the timed protocol. This
includes changing a struct timeval to an explicit structure of two int32_t's. This requires using temporary timevals in several places when calling gettimeofday(), settimeofday(), etc. With this timed now works properly on 64-bit platforms such as Alpha. Obtained from: NetBSD
This commit is contained in:
parent
67bac73ca9
commit
3878fff7db
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=86644
@ -31,6 +31,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)timed.h 8.1 (Berkeley) 6/2/93
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _PROTOCOLS_TIMED_H_
|
||||
@ -44,11 +46,14 @@
|
||||
#define ANYADDR NULL
|
||||
|
||||
struct tsp {
|
||||
u_char tsp_type;
|
||||
u_char tsp_vers;
|
||||
u_short tsp_seq;
|
||||
u_int8_t tsp_type;
|
||||
u_int8_t tsp_vers;
|
||||
u_int16_t tsp_seq;
|
||||
union {
|
||||
struct timeval tspu_time;
|
||||
struct {
|
||||
int32_t tv_sec;
|
||||
int32_t tv_usec;
|
||||
} tspu_time;
|
||||
char tspu_hopcnt;
|
||||
} tsp_u;
|
||||
char tsp_name[MAXHOSTNAMELEN];
|
||||
|
@ -59,7 +59,7 @@ correct(avdelta)
|
||||
{
|
||||
struct hosttbl *htp;
|
||||
int corr;
|
||||
struct timeval adjlocal;
|
||||
struct timeval adjlocal, tmptv;
|
||||
struct tsp to;
|
||||
struct tsp *answer;
|
||||
|
||||
@ -77,11 +77,17 @@ correct(avdelta)
|
||||
|| corr >= MAXADJ*1000
|
||||
|| corr <= -MAXADJ*1000) {
|
||||
htp->need_set = 0;
|
||||
(void)gettimeofday(&to.tsp_time,0);
|
||||
timevaladd(&to.tsp_time, &adjlocal);
|
||||
(void)gettimeofday(&tmptv,0);
|
||||
timevaladd(&tmptv, &adjlocal);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
} else {
|
||||
mstotvround(&to.tsp_time, corr);
|
||||
tmptv.tv_sec = to.tsp_time.tv_sec;
|
||||
tmptv.tv_usec = to.tsp_time.tv_usec;
|
||||
mstotvround(&tmptv, corr);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
to.tsp_type = TSP_ADJTIME;
|
||||
}
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
|
@ -365,7 +365,7 @@ mchgdate(msg)
|
||||
{
|
||||
char tname[MAXHOSTNAMELEN];
|
||||
char olddate[32];
|
||||
struct timeval otime, ntime;
|
||||
struct timeval otime, ntime, tmptv;
|
||||
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
|
||||
@ -377,7 +377,9 @@ mchgdate(msg)
|
||||
(void)gettimeofday(&otime, 0);
|
||||
adj_msg_time(msg,&otime);
|
||||
|
||||
timevalsub(&ntime, &msg->tsp_time, &otime);
|
||||
tmptv.tv_sec = msg->tsp_time.tv_sec;
|
||||
tmptv.tv_usec = msg->tsp_time.tv_usec;
|
||||
timevalsub(&ntime, &tmptv, &otime);
|
||||
if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
|
||||
/*
|
||||
* do not change the clock if we can adjust it
|
||||
@ -392,7 +394,7 @@ mchgdate(msg)
|
||||
logwtmp(&otime, &msg->tsp_time);
|
||||
#else
|
||||
logwtmp("|", "date", "");
|
||||
(void)settimeofday(&msg->tsp_time, 0);
|
||||
(void)settimeofday(&tmptv, 0);
|
||||
logwtmp("{", "date", "");
|
||||
#endif /* sgi */
|
||||
spreadtime();
|
||||
@ -499,6 +501,7 @@ spreadtime()
|
||||
struct hosttbl *htp;
|
||||
struct tsp to;
|
||||
struct tsp *answer;
|
||||
struct timeval tmptv;
|
||||
|
||||
/* Do not listen to the consensus after forcing the time. This is because
|
||||
* the consensus takes a while to reach the time we are dictating.
|
||||
@ -507,7 +510,9 @@ spreadtime()
|
||||
for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)gettimeofday(&to.tsp_time, 0);
|
||||
(void)gettimeofday(&tmptv, 0);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer);
|
||||
if (answer == 0) {
|
||||
@ -772,7 +777,7 @@ newslave(msg)
|
||||
{
|
||||
struct hosttbl *htp;
|
||||
struct tsp *answer, to;
|
||||
struct timeval now;
|
||||
struct timeval now, tmptv;
|
||||
|
||||
if (!fromnet || fromnet->status != MASTER)
|
||||
return;
|
||||
@ -791,7 +796,9 @@ newslave(msg)
|
||||
|| now.tv_sec < fromnet->slvwait.tv_sec) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)gettimeofday(&to.tsp_time, 0);
|
||||
(void)gettimeofday(&tmptv, 0);
|
||||
to.tsp_time.tv_sec = tmptv.tv_sec;
|
||||
to.tsp_time.tv_usec = tmptv.tv_usec;
|
||||
answer = acksend(&to, &htp->addr,
|
||||
htp->name, TSP_ACK,
|
||||
0, htp->noanswer);
|
||||
|
@ -76,7 +76,7 @@ slave()
|
||||
struct sockaddr_in taddr;
|
||||
char tname[MAXHOSTNAMELEN];
|
||||
struct tsp *msg, to;
|
||||
struct timeval ntime, wait;
|
||||
struct timeval ntime, wait, tmptv;
|
||||
time_t tsp_time_sec;
|
||||
struct tsp *answer;
|
||||
int timeout();
|
||||
@ -280,7 +280,9 @@ slave()
|
||||
}
|
||||
|
||||
setmaster(msg);
|
||||
timevalsub(&ntime, &msg->tsp_time, &otime);
|
||||
tmptv.tv_sec = msg->tsp_time.tv_sec;
|
||||
tmptv.tv_usec = msg->tsp_time.tv_usec;
|
||||
timevalsub(&ntime, &tmptv, &otime);
|
||||
if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
|
||||
/*
|
||||
* do not change the clock if we can adjust it
|
||||
@ -295,7 +297,7 @@ slave()
|
||||
logwtmp(&otime, &msg->tsp_time);
|
||||
#else
|
||||
logwtmp("|", "date", "");
|
||||
(void)settimeofday(&msg->tsp_time, 0);
|
||||
(void)settimeofday(&tmptv, 0);
|
||||
logwtmp("{", "date", "");
|
||||
#endif /* sgi */
|
||||
syslog(LOG_NOTICE,
|
||||
|
Loading…
Reference in New Issue
Block a user