]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys: allow drivers to fail when applying step offset
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Apr 2015 13:03:44 +0000 (15:03 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Apr 2015 13:23:47 +0000 (15:23 +0200)
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.

local.c
localp.h
sys_generic.c
sys_linux.c
sys_netbsd.c
sys_solaris.c
sys_sunos.c

diff --git a/local.c b/local.c
index f81c35d6c57bdfdf5bb01e0fc1483ef5f5277d9f..ef4f66b1c3231d6c6a86260e70dd975ece4fd111 100644 (file)
--- a/local.c
+++ b/local.c
@@ -528,7 +528,10 @@ LCL_ApplyStepOffset(double offset)
   if (!check_offset(&raw, offset))
       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 */
   SMT_Reset(&cooked);
index 321985e143ed98b2f1d90496eb8ff9d889dcaf3d..5f993099e1fa2963d75bf85b9412146a1abab4e4 100644 (file)
--- a/localp.h
+++ b/localp.h
@@ -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
    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.
    The number of seconds returned in 'corr' have to be added to the
index 44cb2515221a1684e7ba07e50c3a55fc27f47373..41e36fffb56d0278cc510ae541e7cb1a7902ee8d 100644 (file)
@@ -250,7 +250,7 @@ offset_convert(struct timeval *raw,
 /* ================================================== */
 /* Positive means currently fast of true time, i.e. jump backwards */
 
-static void
+static int
 apply_step_offset(double offset)
 {
   struct timeval old_time, new_time;
@@ -260,13 +260,16 @@ apply_step_offset(double offset)
   UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
 
   if (settimeofday(&new_time, NULL) < 0) {
-    LOG_FATAL(LOGF_SysGeneric, "settimeofday() failed");
+    DEBUG_LOG(LOGF_SysGeneric, "settimeofday() failed");
+    return 0;
   }
 
   LCL_ReadRawTime(&old_time);
   UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
 
   lcl_InvokeDispersionNotifyHandlers(fabs(err));
+
+  return 1;
 }
 
 /* ================================================== */
index d57dde3780a635bbcc3a8f058f9ee3a03a0b5e81..e5ca9a61dbf235c4361a260303a6bc70fe5b67c8 100644 (file)
@@ -100,12 +100,15 @@ our_round(double x)
 /* ================================================== */
 /* Positive means currently fast of true time, i.e. jump backwards */
 
-static void
+static int
 apply_step_offset(double offset)
 {
   if (TMX_ApplyStepOffset(-offset) < 0) {
-    LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
+    DEBUG_LOG(LOGF_SysLinux, "adjtimex() failed");
+    return 0;
   }
+
+  return 1;
 }
 
 /* ================================================== */
index c54de3fbfda6c8535fb2f1fc03dc158e04d1f962..237f35f56160bde18304e73dcbe83017d27a06a0 100644 (file)
@@ -212,7 +212,7 @@ accrue_offset(double offset, double corr_rate)
 /* Positive offset means system clock is fast of true time, therefore
    step backwards */
 
-static void
+static int
 apply_step_offset(double offset)
 {
   struct timeval old_time, new_time, T1;
@@ -226,7 +226,8 @@ apply_step_offset(double offset)
   UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
 
   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);
@@ -234,6 +235,7 @@ apply_step_offset(double offset)
 
   start_adjust();
 
+  return 1;
 }
 
 /* ================================================== */
index 2802a90a2158026d1d8ab0419801692e848ac867..fe8b63a204feaf9751999b20b70b301b03c1414e 100644 (file)
@@ -219,7 +219,7 @@ accrue_offset(double offset, double corr_rate)
 /* Positive offset means system clock is fast of true time, therefore
    step backwards */
 
-static void
+static int
 apply_step_offset(double offset)
 {
   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);
 
   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);
@@ -257,6 +258,8 @@ apply_step_offset(double offset)
   offset_register += rounding_error;
 
   start_adjust();
+
+  return 1;
 }
 
 /* ================================================== */
index 9231dca49785af7b79af303d91432e5d1901b51f..7d0737e946b605f1bacde2a4ae20a33ab9cd623e 100644 (file)
@@ -223,7 +223,7 @@ accrue_offset(double offset, double corr_rate)
 /* Positive offset means system clock is fast of true time, therefore
    step backwards */
 
-static void
+static int
 apply_step_offset(double offset)
 {
   struct timeval old_time, new_time, T1;
@@ -236,7 +236,8 @@ apply_step_offset(double offset)
   UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
 
   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);
@@ -244,6 +245,7 @@ apply_step_offset(double offset)
 
   start_adjust();
 
+  return 1;
 }
 
 /* ================================================== */