[chrony-dev] timeshift option

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Hi all,

For the sole purpose of doing an import we needed a (cassandra) database cluster of 5 nodes to be temporarily timshifted backwards 6 months. At first chrony would work agains the whole idea, but with a small tweak it became a great help. Below you'll find the (quick and dirty) patch that took care of this.

Bottomline is that the "hacked" chronyd process now accepts a -S option specfying the requested timeshift in seconds. This shift is applied to all kernel timekeeping interaction by chronyd, but not to any interaction with external ntp sources. As a result the 5 cluster nodes ran consistently timeshifted w.r.t. the rest of the world, but they had their own clocks accurately synchronized (all nodes had the same -S argument of course).

This may or may not be usefull for other users as wall, so I hereby share the patch.

Cheers,

Rolf Fokkens

--- local.c.warp        2016-02-16 14:25:38.000000000 +0100
+++ local.c     2015-09-09 07:45:24.989696521 +0200
@@ -350,6 +350,7 @@
   if (gettimeofday(result, NULL) < 0) {
     LOG_FATAL(LOGF_Local, "gettimeofday() failed");
   }
+  result->tv_sec -= timeshift;
 }

 /* ================================================== */
--- main.c.orig 2015-09-09 07:44:37.613856619 +0200
+++ main.c      2015-09-09 07:39:44.490820168 +0200
@@ -369,6 +369,8 @@

   LOG_Initialise();

+  timeshift = 0;
+
   /* Parse command line options */
   while (++argv, (--argc)>0) {

@@ -425,6 +427,13 @@
printf("Usage: %s [-4|-6] [-n|-d] [-q|-Q] [-r] [-R] [-s] [-f FILE|COMMAND...]\n",
              progname);
       return 0;
+    } else if (!strcmp("-S", *argv)) {
+      ++argv, --argc;
+      if (argc == 0) {
+        LOG_FATAL(LOGF_Main, "Missing timeshift argument");
+      } else {
+        timeshift = atol (*argv);
+      }
     } else if (*argv[0] == '-') {
LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
     } else {
--- ntp_io.c.warp       2016-02-16 14:25:38.000000000 +0100
+++ ntp_io.c    2015-09-09 07:45:57.709585538 +0200
@@ -560,6 +560,7 @@
         struct timeval tv;

         memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
+        tv.tv_sec -= timeshift;
         LCL_CookTime(&tv, &now, &now_err);
       }
 #endif
--- privops.c.warp      2016-02-16 14:25:38.000000000 +0100
+++ privops.c   2015-09-09 07:46:22.100502811 +0200
@@ -242,7 +242,10 @@
 static void
 do_set_time(const ReqSetTime *req, PrvResponse *res)
 {
-  res->rc = settimeofday(&req->tv, NULL);
+  struct timeval tv = req->tv;
+
+  tv.tv_sec += timeshift;
+  res->rc = settimeofday(&tv, NULL);
   if (res->rc)
     res->res_errno = errno;
 }
@@ -530,13 +533,16 @@
 {
   PrvRequest req;
   PrvResponse res;
+  struct timeval tv = *tp;

   /* only support setting the time */
   assert(tp != NULL);
   assert(tzp == NULL);

-  if (!have_helper())
-    return settimeofday(tp, NULL);
+  if (!have_helper()) {
+    tv.tv_sec += timeshift;
+    return settimeofday(&tv, NULL);
+  }

   memset(&req, 0, sizeof (req));
   req.op = OP_SETTIME;
--- sys_generic.c.warp  2016-02-16 14:25:38.000000000 +0100
+++ sys_generic.c       2015-09-09 07:46:45.390423789 +0200
@@ -330,6 +330,8 @@
   LCL_ReadRawTime(&old_time);
   UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);

+  new_time.tv_sec += timeshift;
+
   if (PRV_SetTime(&new_time, NULL) < 0) {
     DEBUG_LOG(LOGF_SysGeneric, "settimeofday() failed");
     return 0;
--- util.c.orig 2015-09-09 07:42:43.222244551 +0200
+++ util.c      2015-09-09 07:43:10.391151902 +0200
@@ -25,6 +25,8 @@
   Various utility functions
   */

+long timeshift = 0;
+
 #include "config.h"

 #include "sysincl.h"
--- util.h.orig 2015-09-09 07:47:39.582242882 +0200
+++ util.h      2015-09-09 07:43:29.374087422 +0200
@@ -34,6 +34,8 @@
 #include "candm.h"
 #include "hash.h"

+extern long timeshift;
+
 /* Convert a timeval into a floating point number of seconds */
 extern void UTI_TimevalToDouble(struct timeval *a, double *b);

--- sys_timex.c.warp    2016-02-16 14:25:38.000000000 +0100
+++ sys_timex.c 2016-09-08 07:54:07.097460330 +0200
@@ -34,6 +34,7 @@
 #include "sys_generic.h"
 #include "sys_timex.h"
 #include "logging.h"
+#include "util.h"

 #ifdef PRIVOPS_ADJUSTTIMEX
 #define NTP_ADJTIME PRV_AdjustTimex
@@ -245,5 +246,7 @@
                 txc->modes, strerror(errno));
   }

+  txc->time.tv_sec -= timeshift;
+
   return state;
 }
(END)


--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/