FreeBSD/usr.sbin/timed/timed/correct.c
/*
 * sends to the slaves the corrections for their clocks after fixing our
 * own
 */
sends to the slaves the corrections for their clocks after fixing our
own
sends to the slaves the corrections for their clocks after fixing our own
void
correct(long avdelta)
{
	struct hosttbl *htp;
	int corr;
	struct timeval adjlocal, tmptv;
	struct tsp to;
	struct tsp *answer;
	mstotvround(&adjlocal, avdelta);
	for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
		if (htp->delta != HOSTDOWN)  {
			corr = avdelta - htp->delta;
			if (htp->need_set
			    || corr >= MAXADJ*1000
			    || corr <= -MAXADJ*1000) {
				htp->need_set = 0;
				(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 {
				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);
			answer = acksend(&to, &htp->addr, htp->name,
					 TSP_ACK, 0, 0);
			if (!answer) {
				htp->delta = HOSTDOWN;
				syslog(LOG_WARNING,
				       "no reply to time correction from %s",
				       htp->name);
				if (++htp->noanswer >= LOSTHOST) {
					if (trace) {
						fprintf(fd,
					     "purging %s for not answering\n",
							htp->name);
						(void)fflush(fd);
					}
					htp = remmach(htp);
				}
			}
		}
	}
	adjclock(&adjlocal);
}
void correct ( long avdelta ) { struct hosttbl * htp ; int corr ; struct timeval adjlocal , tmptv ; struct tsp to ; struct tsp * answer ; mstotvround ( & adjlocal , avdelta ) ; for ( htp = self . l_fwd ; htp != & self ; htp = htp -> l_fwd ) { if ( htp -> delta != HOSTDOWN ) { corr = avdelta - htp -> delta ; if ( htp -> need_set || corr >= MAXADJ * 1000 || corr <= - MAXADJ * 1000 ) { htp -> need_set = 0 ; ( 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 { 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 ) ; answer = acksend ( & to , & htp -> addr , htp -> name , TSP_ACK , 0 , 0 ) ; if ( ! answer ) { htp -> delta = HOSTDOWN ; syslog ( LOG_WARNING , " " , htp -> name ) ; if ( ++ htp -> noanswer >= LOSTHOST ) { if ( trace ) { fprintf ( fd , " \n " , htp -> name ) ; ( void ) fflush ( fd ) ; } htp = remmach ( htp ) ; } } } } adjclock ( & adjlocal ) ; }
sends to the slaves the corrections for their clocks after fixing our
 own
sends to the slaves the corrections for their clocks after fixing our own
/* If the other machine is off in the weeds, set its time directly.
 *	If a slave gets the wrong day, the original code would simply
 *	fix the minutes.  If you fix a network partition, you can get
 *	into such situations.
 */ /*
	 * adjust our own clock now that we are not sending it out
	 */