From 9f1e9b7b8957136695856043f7f82179a65b16b4 Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 20 Nov 2001 06:36:09 +0000 Subject: 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 --- usr.sbin/timed/timed/correct.c | 14 ++++++++++---- usr.sbin/timed/timed/master.c | 19 +++++++++++++------ usr.sbin/timed/timed/slave.c | 8 +++++--- 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'usr.sbin/timed') diff --git a/usr.sbin/timed/timed/correct.c b/usr.sbin/timed/timed/correct.c index 1e13654..1e4e2dd 100644 --- a/usr.sbin/timed/timed/correct.c +++ b/usr.sbin/timed/timed/correct.c @@ -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); diff --git a/usr.sbin/timed/timed/master.c b/usr.sbin/timed/timed/master.c index ac4ff45..c0e605b 100644 --- a/usr.sbin/timed/timed/master.c +++ b/usr.sbin/timed/timed/master.c @@ -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); diff --git a/usr.sbin/timed/timed/slave.c b/usr.sbin/timed/timed/slave.c index 4029ee8..9c76d7e 100644 --- a/usr.sbin/timed/timed/slave.c +++ b/usr.sbin/timed/timed/slave.c @@ -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 @@ loop: } 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 @@ loop: 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, -- cgit v1.1