sys: allow drivers to fail when applying step offset

Different systems may consider different time values to be valid.
Don't exit on settimeofday()/adjtimex() error in case the check in
UTI_IsTimeOffsetSane() isn't restrictive enough.
This commit is contained in:
Miroslav Lichvar 2015-04-07 15:03:44 +02:00
parent 42774ee851
commit f6a9c5c1b7
7 changed files with 28 additions and 12 deletions

View file

@ -528,7 +528,10 @@ LCL_ApplyStepOffset(double offset)
if (!check_offset(&raw, offset)) if (!check_offset(&raw, offset))
return 0; return 0;
(*drv_apply_step_offset)(offset); if (!(*drv_apply_step_offset)(offset)) {
LOG(LOGS_ERR, LOGF_Local, "Could not step clock");
return 0;
}
/* Reset smoothing on all clock steps */ /* Reset smoothing on all clock steps */
SMT_Reset(&cooked); SMT_Reset(&cooked);

View file

@ -47,7 +47,7 @@ typedef void (*lcl_AccrueOffsetDriver)(double offset, double corr_rate);
/* System driver to apply a step offset. A positive argument means step /* System driver to apply a step offset. A positive argument means step
the clock forwards. */ the clock forwards. */
typedef void (*lcl_ApplyStepOffsetDriver)(double offset); typedef int (*lcl_ApplyStepOffsetDriver)(double offset);
/* System driver to convert a raw time to an adjusted (cooked) time. /* System driver to convert a raw time to an adjusted (cooked) time.
The number of seconds returned in 'corr' have to be added to the The number of seconds returned in 'corr' have to be added to the

View file

@ -250,7 +250,7 @@ offset_convert(struct timeval *raw,
/* ================================================== */ /* ================================================== */
/* Positive means currently fast of true time, i.e. jump backwards */ /* Positive means currently fast of true time, i.e. jump backwards */
static void static int
apply_step_offset(double offset) apply_step_offset(double offset)
{ {
struct timeval old_time, new_time; struct timeval old_time, new_time;
@ -260,13 +260,16 @@ apply_step_offset(double offset)
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, NULL) < 0) { if (settimeofday(&new_time, NULL) < 0) {
LOG_FATAL(LOGF_SysGeneric, "settimeofday() failed"); DEBUG_LOG(LOGF_SysGeneric, "settimeofday() failed");
return 0;
} }
LCL_ReadRawTime(&old_time); LCL_ReadRawTime(&old_time);
UTI_DiffTimevalsToDouble(&err, &old_time, &new_time); UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
lcl_InvokeDispersionNotifyHandlers(fabs(err)); lcl_InvokeDispersionNotifyHandlers(fabs(err));
return 1;
} }
/* ================================================== */ /* ================================================== */

View file

@ -100,12 +100,15 @@ our_round(double x)
/* ================================================== */ /* ================================================== */
/* Positive means currently fast of true time, i.e. jump backwards */ /* Positive means currently fast of true time, i.e. jump backwards */
static void static int
apply_step_offset(double offset) apply_step_offset(double offset)
{ {
if (TMX_ApplyStepOffset(-offset) < 0) { if (TMX_ApplyStepOffset(-offset) < 0) {
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); DEBUG_LOG(LOGF_SysLinux, "adjtimex() failed");
return 0;
} }
return 1;
} }
/* ================================================== */ /* ================================================== */

View file

@ -212,7 +212,7 @@ accrue_offset(double offset, double corr_rate)
/* Positive offset means system clock is fast of true time, therefore /* Positive offset means system clock is fast of true time, therefore
step backwards */ step backwards */
static void static int
apply_step_offset(double offset) apply_step_offset(double offset)
{ {
struct timeval old_time, new_time, T1; struct timeval old_time, new_time, T1;
@ -226,7 +226,8 @@ apply_step_offset(double offset)
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, NULL) < 0) { if (settimeofday(&new_time, NULL) < 0) {
LOG_FATAL(LOGF_SysNetBSD, "settimeofday() failed"); DEBUG_LOG(LOGF_SysNetBSD, "settimeofday() failed");
return 0;
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -234,6 +235,7 @@ apply_step_offset(double offset)
start_adjust(); start_adjust();
return 1;
} }
/* ================================================== */ /* ================================================== */

View file

@ -219,7 +219,7 @@ accrue_offset(double offset, double corr_rate)
/* Positive offset means system clock is fast of true time, therefore /* Positive offset means system clock is fast of true time, therefore
step backwards */ step backwards */
static void static int
apply_step_offset(double offset) apply_step_offset(double offset)
{ {
struct timeval old_time, new_time, rounded_new_time, T1; struct timeval old_time, new_time, rounded_new_time, T1;
@ -248,7 +248,8 @@ apply_step_offset(double offset)
UTI_DiffTimevalsToDouble(&rounding_error, &rounded_new_time, &new_time); UTI_DiffTimevalsToDouble(&rounding_error, &rounded_new_time, &new_time);
if (settimeofday(&new_time, NULL) < 0) { if (settimeofday(&new_time, NULL) < 0) {
LOG_FATAL(LOGF_SysSolaris, "settimeofday() failed"); DEBUG_LOG(LOGF_SysSolaris, "settimeofday() failed");
return 0;
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -257,6 +258,8 @@ apply_step_offset(double offset)
offset_register += rounding_error; offset_register += rounding_error;
start_adjust(); start_adjust();
return 1;
} }
/* ================================================== */ /* ================================================== */

View file

@ -223,7 +223,7 @@ accrue_offset(double offset, double corr_rate)
/* Positive offset means system clock is fast of true time, therefore /* Positive offset means system clock is fast of true time, therefore
step backwards */ step backwards */
static void static int
apply_step_offset(double offset) apply_step_offset(double offset)
{ {
struct timeval old_time, new_time, T1; struct timeval old_time, new_time, T1;
@ -236,7 +236,8 @@ apply_step_offset(double offset)
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
if (settimeofday(&new_time, NULL) < 0) { if (settimeofday(&new_time, NULL) < 0) {
LOG_FATAL(LOGF_SysSunOS, "settimeofday() failed"); DEBUG_LOG(LOGF_SysSunOS, "settimeofday() failed");
return 0;
} }
UTI_AddDoubleToTimeval(&T0, offset, &T1); UTI_AddDoubleToTimeval(&T0, offset, &T1);
@ -244,6 +245,7 @@ apply_step_offset(double offset)
start_adjust(); start_adjust();
return 1;
} }
/* ================================================== */ /* ================================================== */