Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/libntp/systime.c
Show All 19 Lines | |||||
#endif | #endif | ||||
#ifdef HAVE_UTMP_H | #ifdef HAVE_UTMP_H | ||||
# include <utmp.h> | # include <utmp.h> | ||||
#endif /* HAVE_UTMP_H */ | #endif /* HAVE_UTMP_H */ | ||||
#ifdef HAVE_UTMPX_H | #ifdef HAVE_UTMPX_H | ||||
# include <utmpx.h> | # include <utmpx.h> | ||||
#endif /* HAVE_UTMPX_H */ | #endif /* HAVE_UTMPX_H */ | ||||
int allow_panic = FALSE; /* allow panic correction (-g) */ | |||||
int enable_panic_check = TRUE; /* Can we check allow_panic's state? */ | |||||
#ifndef USE_COMPILETIME_PIVOT | #ifndef USE_COMPILETIME_PIVOT | ||||
# define USE_COMPILETIME_PIVOT 1 | # define USE_COMPILETIME_PIVOT 1 | ||||
#endif | #endif | ||||
/* | /* | ||||
* These routines (get_systime, step_systime, adj_systime) implement an | * These routines (get_systime, step_systime, adj_systime) implement an | ||||
* interface between the system independent NTP clock and the Unix | * interface between the system independent NTP clock and the Unix | ||||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | adj_systime( | ||||
* The Windows port adj_systime() depends on being called each | * The Windows port adj_systime() depends on being called each | ||||
* second even when there's no additional correction, to allow | * second even when there's no additional correction, to allow | ||||
* emulation of adjtime() behavior on top of an API that simply | * emulation of adjtime() behavior on top of an API that simply | ||||
* sets the current rate. This POSIX implementation needs to | * sets the current rate. This POSIX implementation needs to | ||||
* ignore invocations with zero correction, otherwise ongoing | * ignore invocations with zero correction, otherwise ongoing | ||||
* EVNT_NSET adjtime() can be aborted by a tiny adjtime() | * EVNT_NSET adjtime() can be aborted by a tiny adjtime() | ||||
* triggered by sys_residual. | * triggered by sys_residual. | ||||
*/ | */ | ||||
if (0. == now) | if (0. == now) { | ||||
if (enable_panic_check && allow_panic) { | |||||
msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); | |||||
INSIST(!allow_panic); | |||||
} | |||||
return TRUE; | return TRUE; | ||||
} | |||||
/* | /* | ||||
* Most Unix adjtime() implementations adjust the system clock | * Most Unix adjtime() implementations adjust the system clock | ||||
* in microsecond quanta, but some adjust in 10-ms quanta. We | * in microsecond quanta, but some adjust in 10-ms quanta. We | ||||
* carefully round the adjustment to the nearest quantum, then | * carefully round the adjustment to the nearest quantum, then | ||||
* adjust in quanta and keep the residue for later. | * adjust in quanta and keep the residue for later. | ||||
*/ | */ | ||||
dtemp = now + sys_residual; | dtemp = now + sys_residual; | ||||
Show All 20 Lines | adj_systime( | ||||
if (isneg) { | if (isneg) { | ||||
adjtv.tv_sec = -adjtv.tv_sec; | adjtv.tv_sec = -adjtv.tv_sec; | ||||
adjtv.tv_usec = -adjtv.tv_usec; | adjtv.tv_usec = -adjtv.tv_usec; | ||||
sys_residual = -sys_residual; | sys_residual = -sys_residual; | ||||
} | } | ||||
if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) { | if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) { | ||||
if (adjtime(&adjtv, &oadjtv) < 0) { | if (adjtime(&adjtv, &oadjtv) < 0) { | ||||
msyslog(LOG_ERR, "adj_systime: %m"); | msyslog(LOG_ERR, "adj_systime: %m"); | ||||
if (enable_panic_check && allow_panic) { | |||||
msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); | |||||
} | |||||
return FALSE; | return FALSE; | ||||
} | } | ||||
} | } | ||||
if (enable_panic_check && allow_panic) { | |||||
msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); | |||||
} | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
#endif | #endif | ||||
/* | /* | ||||
* step_systime - step the system clock. | * step_systime - step the system clock. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | #endif | ||||
L_ADD(&fp_sys, &fp_ofs); | L_ADD(&fp_sys, &fp_ofs); | ||||
/* unfold the new system time */ | /* unfold the new system time */ | ||||
timetv = lfp_stamp_to_tval(fp_sys, &pivot); | timetv = lfp_stamp_to_tval(fp_sys, &pivot); | ||||
/* now set new system time */ | /* now set new system time */ | ||||
if (ntp_set_tod(&timetv, NULL) != 0) { | if (ntp_set_tod(&timetv, NULL) != 0) { | ||||
msyslog(LOG_ERR, "step-systime: %m"); | msyslog(LOG_ERR, "step-systime: %m"); | ||||
if (enable_panic_check && allow_panic) { | |||||
msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); | |||||
} | |||||
return FALSE; | return FALSE; | ||||
} | } | ||||
/* <--- time-critical path ended with 'ntp_set_tod()' <--- */ | /* <--- time-critical path ended with 'ntp_set_tod()' <--- */ | ||||
sys_residual = 0; | sys_residual = 0; | ||||
lamport_violated = (step < 0); | lamport_violated = (step < 0); | ||||
if (step_callback) | if (step_callback) | ||||
Show All 10 Lines | #endif | ||||
* FreeBSD, for example, has: | * FreeBSD, for example, has: | ||||
* struct utmp { | * struct utmp { | ||||
* char ut_line[UT_LINESIZE]; | * char ut_line[UT_LINESIZE]; | ||||
* char ut_name[UT_NAMESIZE]; | * char ut_name[UT_NAMESIZE]; | ||||
* char ut_host[UT_HOSTSIZE]; | * char ut_host[UT_HOSTSIZE]; | ||||
* long ut_time; | * long ut_time; | ||||
* }; | * }; | ||||
* and appends line="|", name="date", host="", time for the OLD | * and appends line="|", name="date", host="", time for the OLD | ||||
* and appends line="{", name="date", host="", time for the NEW | * and appends line="{", name="date", host="", time for the NEW // } | ||||
* to _PATH_WTMP . | * to _PATH_WTMP . | ||||
* | * | ||||
* Some OSes have utmp, some have utmpx. | * Some OSes have utmp, some have utmpx. | ||||
*/ | */ | ||||
/* | /* | ||||
* Write old and new time entries in utmp and wtmp if step | * Write old and new time entries in utmp and wtmp if step | ||||
* adjustment is greater than one second. | * adjustment is greater than one second. | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
# ifdef HAVE_UPDWTMPX | # ifdef HAVE_UPDWTMPX | ||||
updwtmpx(WTMPX_FILE, &utx); | updwtmpx(WTMPX_FILE, &utx); | ||||
# else /* not HAVE_UPDWTMPX */ | # else /* not HAVE_UPDWTMPX */ | ||||
# endif /* not HAVE_UPDWTMPX */ | # endif /* not HAVE_UPDWTMPX */ | ||||
# else /* not HAVE_PUTUTXLINE */ | # else /* not HAVE_PUTUTXLINE */ | ||||
# endif /* not HAVE_PUTUTXLINE */ | # endif /* not HAVE_PUTUTXLINE */ | ||||
#endif /* UPDATE_WTMPX */ | #endif /* UPDATE_WTMPX */ | ||||
} | |||||
if (enable_panic_check && allow_panic) { | |||||
msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); | |||||
INSIST(!allow_panic); | |||||
} | } | ||||
return TRUE; | return TRUE; | ||||
} | } | ||||
#endif /* !SIM */ | #endif /* !SIM */ |