FreeBSD/contrib/ntp/ntpdate/ntpdate.c
/*
 * clock_adjust - process what we've received, and adjust the time
 *		 if we got anything decent.
 */
process what we've received, and adjust the time
if we got anything decent.
process what we ' ve received and adjust the time if we got anything decent .
static int
clock_adjust(void)
{
	register struct server *sp, *server;
	int dostep;
	for (sp = sys_servers; sp != NULL; sp = sp->next_server)
		clock_filter(sp);
	server = clock_select();
	if (debug || simple_query) {
		for (sp = sys_servers; sp != NULL; sp = sp->next_server)
			printserver(sp, stdout);
	}
	if (server == 0) {
		msyslog(LOG_ERR,
			"no server suitable for synchronization found");
		return(1);
	}
	if (always_step) {
		dostep = 1;
	} else if (never_step) {
		dostep = 0;
	} else {
		u_fp absoffset;
		if (server->soffset < 0)
			absoffset = 1u + (u_fp)(-(server->soffset + 1));
		else
			absoffset = (u_fp)server->soffset;
		dostep = (absoffset >= NTPDATE_THRESHOLD);
	}
	if (dostep) {
		if (simple_query || debug || l_step_systime(&server->offset)){
			msyslog(LOG_NOTICE, "step time server %s offset %s sec",
				stoa(&server->srcadr),
				lfptoa(&server->offset, 6));
		}
	} else {
#ifndef SYS_WINNT
		if (simple_query || l_adj_systime(&server->offset)) {
			msyslog(LOG_NOTICE, "adjust time server %s offset %s sec",
				stoa(&server->srcadr),
				lfptoa(&server->offset, 6));
		}
#else
		printf("\nThe -b option is required by ntpdate on Windows NT platforms\n");
		exit(1);
#endif 
	}
	return(0);
}
static int clock_adjust ( void ) { register struct server * sp , * server ; int dostep ; for ( sp = sys_servers ; sp != NULL ; sp = sp -> next_server ) clock_filter ( sp ) ; server = clock_select ( ) ; if ( debug || simple_query ) { for ( sp = sys_servers ; sp != NULL ; sp = sp -> next_server ) printserver ( sp , stdout ) ; } if ( server == 0 ) { msyslog ( LOG_ERR , " " ) ; return ( 1 ) ; } if ( always_step ) { dostep = 1 ; } else if ( never_step ) { dostep = 0 ; } else { u_fp absoffset ; if ( server -> soffset < 0 ) absoffset = 1u + ( u_fp ) ( - ( server -> soffset + 1 ) ) ; else absoffset = ( u_fp ) server -> soffset ; dostep = ( absoffset >= NTPDATE_THRESHOLD ) ; } if ( dostep ) { if ( simple_query || debug || l_step_systime ( & server -> offset ) ) { msyslog ( LOG_NOTICE , " " , stoa ( & server -> srcadr ) , lfptoa ( & server -> offset , 6 ) ) ; } } else { #ifndef SYS_WINNT if ( simple_query || l_adj_systime ( & server -> offset ) ) { msyslog ( LOG_NOTICE , " " , stoa ( & server -> srcadr ) , lfptoa ( & server -> offset , 6 ) ) ; } #else printf ( " \n \n " ) ; exit ( 1 ) ; #endif } return ( 0 ) ; }
clock_adjust - process what we've received, and adjust the time
               if we got anything decent.
clock_adjust - process what we ' ve received and adjust the time if we got anything decent .
/* [Bug 3023] get absolute difference, avoiding signed
		 * integer overflow like hell.
		 */ /* The NT SetSystemTimeAdjustment() call achieves slewing by
		 * changing the clock frequency. This means that we cannot specify
		 * it to slew the clock by a definite amount and then stop like
		 * the Unix adjtime() routine. We can technically adjust the clock
		 * frequency, have ntpdate sleep for a while, and then wake
		 * up and reset the clock frequency, but this might cause some
		 * grief if the user attempts to run ntpd immediately after
		 * ntpdate and the socket is in use.
		 */ /* SYS_WINNT */