summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2001-11-20 06:36:09 +0000
committerjhb <jhb@FreeBSD.org>2001-11-20 06:36:09 +0000
commit9f1e9b7b8957136695856043f7f82179a65b16b4 (patch)
tree348013711bf9fb5908dff97b1ce0bd3ac962a9ab
parent3212bd4f7f7d6d47e087468730dbbcb390f12af9 (diff)
downloadFreeBSD-src-9f1e9b7b8957136695856043f7f82179a65b16b4.zip
FreeBSD-src-9f1e9b7b8957136695856043f7f82179a65b16b4.tar.gz
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
-rw-r--r--include/protocols/timed.h13
-rw-r--r--usr.sbin/timed/timed/correct.c14
-rw-r--r--usr.sbin/timed/timed/master.c19
-rw-r--r--usr.sbin/timed/timed/slave.c8
4 files changed, 37 insertions, 17 deletions
diff --git a/include/protocols/timed.h b/include/protocols/timed.h
index 6c6a05e..75b27ed 100644
--- a/include/protocols/timed.h
+++ b/include/protocols/timed.h
@@ -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];
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,
OpenPOWER on IntegriCloud