]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys: add apply_step_offset function to generic driver
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 20 May 2014 15:05:05 +0000 (17:05 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 20 May 2014 15:14:33 +0000 (17:14 +0200)
Move the generic code away from the Linux driver and keep there only
stepping by adjtimex(ADJ_SETOFFSET).

sys_generic.c
sys_linux.c

index 5232b7657d87d33430989b28e47be1b1837eec4f..d6c109d859587a16711ed968f20bb33cdebe4eeb 100644 (file)
@@ -235,6 +235,28 @@ offset_convert(struct timeval *raw,
     *err = fabs(duration) <= max_freq_change_delay ? slew_error : 0.0;
 }
 
+/* ================================================== */
+/* Positive means currently fast of true time, i.e. jump backwards */
+
+static void
+apply_step_offset(double offset)
+{
+  struct timeval old_time, new_time;
+  double err;
+
+  LCL_ReadRawTime(&old_time);
+  UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
+
+  if (settimeofday(&new_time, NULL) < 0) {
+    LOG_FATAL(LOGF_SysGeneric, "settimeofday() failed");
+  }
+
+  LCL_ReadRawTime(&old_time);
+  UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
+
+  lcl_InvokeDispersionNotifyHandlers(fabs(err));
+}
+
 /* ================================================== */
 
 void
@@ -254,7 +276,8 @@ SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_set_freq_dela
   offset_register = 0.0;
 
   lcl_RegisterSystemDrivers(read_frequency, set_frequency,
-                            accrue_offset, sys_apply_step_offset,
+                            accrue_offset, sys_apply_step_offset ?
+                              sys_apply_step_offset : apply_step_offset,
                             offset_convert, sys_set_leap);
 
   LCL_AddParameterChangeHandler(handle_step, NULL);
index 078604f5b3f10a8ac53887ef3fae03201e76c73c..930f55f1c081374a24e9fe26b74570320dde7ef6 100644 (file)
@@ -52,7 +52,6 @@ int LockAll = 0;
 #include <grp.h>
 #endif
 
-#include "localp.h"
 #include "sys_generic.h"
 #include "sys_linux.h"
 #include "conf.h"
@@ -110,30 +109,8 @@ our_round(double x) {
 static void
 apply_step_offset(double offset)
 {
-  struct timeval old_time, new_time;
-  double err;
-
-  if (have_setoffset) {
-    if (TMX_ApplyStepOffset(-offset) < 0) {
-      LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
-    }
-  } else {
-    if (gettimeofday(&old_time, NULL) < 0) {
-      LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
-    }
-
-    UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
-
-    if (settimeofday(&new_time, NULL) < 0) {
-      LOG_FATAL(LOGF_SysLinux, "settimeofday() failed");
-    }
-
-    if (gettimeofday(&old_time, NULL) < 0) {
-      LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
-    }
-
-    UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
-    lcl_InvokeDispersionNotifyHandlers(fabs(err));
+  if (TMX_ApplyStepOffset(-offset) < 0) {
+    LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
   }
 }
 
@@ -417,7 +394,8 @@ SYS_Linux_Initialise(void)
   SYS_Generic_CompleteFreqDriver(1.0e6 * max_tick_bias / nominal_tick,
                                  1.0 / tick_update_hz,
                                  read_frequency, set_frequency,
-                                 apply_step_offset, set_leap);
+                                 have_setoffset ? apply_step_offset : NULL,
+                                 set_leap);
 }
 
 /* ================================================== */