/* * Copyright (c) 1985 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #ifndef lint static char sccsid[] = "@(#)correct.c 2.3 (Berkeley) 5/28/86"; #endif not lint #include "globals.h" #include #ifdef MEASURE extern FILE *fp; #endif /* * `correct' sends to the slaves the corrections for their clocks */ correct(avdelta) long avdelta; { int i; long corr; struct timeval adjlocal; struct tsp msgs; struct timeval mstotvround(); struct tsp *answer, *acksend(); #ifdef MEASURE for(i=0; i= 3) *x = *x-temp+5; else { if (temp <= -3) *x = *x - temp -5; else *x = *x-temp; } adj.tv_sec = *x/1000; adj.tv_usec = (*x-adj.tv_sec*1000)*1000; if (adj.tv_usec < 0) { adj.tv_usec += 1000000; adj.tv_sec--; } return(adj); } adjclock(corr) struct timeval *corr; { struct timeval now; if (timerisset(corr)) { if (corr->tv_sec < MAXADJ && corr->tv_sec > - MAXADJ) { (void)adjtime(corr, (struct timeval *)0); } else { syslog(LOG_WARNING, "clock correction too large to adjust (%ld sec)", corr->tv_sec); (void) gettimeofday(&now, (struct timezone *)0); timevaladd(&now, corr); if (settimeofday(&now, (struct timezone *)0) < 0) syslog(LOG_ERR, "can't set time"); } } } timevaladd(tv1, tv2) register struct timeval *tv1, *tv2; { tv1->tv_sec += tv2->tv_sec; tv1->tv_usec += tv2->tv_usec; if (tv1->tv_usec >= 1000000) { tv1->tv_sec++; tv1->tv_usec -= 1000000; } if (tv1->tv_usec < 0) { tv1->tv_sec--; tv1->tv_usec += 1000000; } }