* Copyright (c) 1985 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)correct.c 2.6 (Berkeley) 6/1/90";
#include <protocols/timed.h>
* `correct' sends to the slaves the corrections for their clocks
struct timeval
mstotvround();
struct tsp
*answer
, *acksend();
for(i
=0; i
<slvcount
; i
++) {
if (hp
[i
].delta
== HOSTDOWN
)
fprintf(fp
, "%s\t", "down");
fprintf(fp
, "%d\t", hp
[i
].delta
);
corr
= avdelta
- hp
[0].delta
;
adjlocal
= mstotvround(&corr
);
fprintf(fp
, "%d\t", corr
);
for(i
=1; i
<slvcount
; i
++) {
if (hp
[i
].delta
!= HOSTDOWN
) {
corr
= avdelta
- hp
[i
].delta
;
msgs
.tsp_time
= mstotvround(&corr
);
msgs
.tsp_type
= (u_char
)TSP_ADJTIME
;
(void)strcpy(msgs
.tsp_name
, hostname
);
answer
= acksend(&msgs
, &hp
[i
].addr
, hp
[i
].name
,
TSP_ACK
, (struct netinfo
*)NULL
);
fprintf(fp
, "%s\t", "down");
fprintf(fp
, "%d\t", corr
);
fprintf(fp
, "%s\t", "down");
* `mstotvround' rounds up the value of the argument to the
* nearest multiple of five, and converts it into a timeval
struct timeval
mstotvround(x
)
adj
.tv_usec
= (*x
-adj
.tv_sec
*1000)*1000;
if (corr
->tv_sec
< MAXADJ
&& corr
->tv_sec
> - MAXADJ
) {
(void)adjtime(corr
, (struct timeval
*)0);
"clock correction too large to adjust (%d sec)",
(void) gettimeofday(&now
, (struct timezone
*)0);
if (settimeofday(&now
, (struct timezone
*)0) < 0)
syslog(LOG_ERR
, "can't set time");
register struct timeval
*tv1
, *tv2
;
tv1
->tv_sec
+= tv2
->tv_sec
;
tv1
->tv_usec
+= tv2
->tv_usec
;
if (tv1
->tv_usec
>= 1000000) {