]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add leap status to tracking log and report
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 24 Feb 2012 09:54:37 +0000 (10:54 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 24 Feb 2012 10:06:20 +0000 (11:06 +0100)
candm.h
chrony.texi
client.c
cmdmon.c
reference.c
reports.h

diff --git a/candm.h b/candm.h
index a6edc6ec69957c73ad7c2fa7009dedd27d202c1e..a0efbd1ebe33a184c5846711e062f7aa0f55865a 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -530,7 +530,8 @@ typedef struct {
 typedef struct {
   uint32_t ref_id;
   IPAddr ip_addr;
-  uint32_t stratum;
+  uint16_t stratum;
+  uint16_t leap_status;
   Timeval ref_time;
   Float current_correction;
   Float last_offset;
index b09da9266ff30475af763a2bbfe28438761e5b0c..7f3d57108cf2c9cf008147e73939ea3df6cc2a74 100644 (file)
@@ -2021,7 +2021,7 @@ An example line (which actually appears as a single line in the file)
 from the tracking log file is shown below.
 
 @example
-1998-07-22 05:40:50 158.152.1.76     3    340.529      1.606  1.046e-03
+2012-02-23 05:40:50 158.152.1.76     3    340.529      1.606  1.046e-03 N
 @end example
 
 The columns are as follows (the quantities in square brackets are the
@@ -2029,7 +2029,7 @@ values from the example line above) :
 
 @enumerate 1
 @item
-Date [1998-07-22]
+Date [2012-02-03]
 @item
 Hour:Minute:Second [05:40:50].  Note that the date/time pair is
 expressed in UTC, not the local time zone.
@@ -2047,6 +2047,10 @@ The error bounds on the frequency (in ppm) [1.606]
 The estimated local offset at the epoch (which is rapidly corrected by
 slewing the local clock.  (In seconds, positive indicates the local
 system is fast of UTC). [1.046e-3]
+@item
+Leap status (@code{N} means normal, @code{+} means that the last minute
+of this month has 61 seconds, @code{-} means that the last minute of the month
+has 59 seconds, @code{?} means the clock is not currently synchronised.) [N]
 @end enumerate
 
 A banner is periodically written to the log file to indicate the
@@ -4265,6 +4269,10 @@ clock_error <= root_dispersion + (0.5 * |root_delay|)
 @item Update interval
 This is the interval between the last two clock updates.
 
+@item Leap status
+This is the leap status, which can be @code{Normal}, @code{Insert second},
+@code{Delete second} or @code{Not synchronised}.
+
 @end table
 @c }}}
 @c {{{ trimrtc
index 193b67bfa4af74ecf4b0220f2afca767cb2a861d..f5f24cbd3431ac936415d41706b2513124d082b1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1887,6 +1887,7 @@ process_cmd_tracking(char *line)
   double root_delay;
   double root_dispersion;
   double last_update_interval;
+  const char *leap_status;
   
   request.command = htons(REQ_TRACKING);
   if (request_reply(&request, &reply, RPY_TRACKING, 0)) {
@@ -1906,8 +1907,26 @@ process_cmd_tracking(char *line)
       ref_ip = host;
     }
     
+    switch (ntohs(reply.data.tracking.leap_status)) {
+      case LEAP_Normal:
+        leap_status = "Normal";
+        break;
+      case LEAP_InsertSecond:
+        leap_status = "Insert second";
+        break;
+      case LEAP_DeleteSecond:
+        leap_status = "Delete second";
+        break;
+      case LEAP_Unsynchronised:
+        leap_status = "Not synchronised";
+        break;
+      default:
+        leap_status = "Unknown";
+        break;
+    }
+
     printf("Reference ID    : %lu.%lu.%lu.%lu (%s)\n", a, b, c, d, ref_ip);
-    printf("Stratum         : %lu\n", (unsigned long) ntohl(reply.data.tracking.stratum));
+    printf("Stratum         : %lu\n", (unsigned long) ntohs(reply.data.tracking.stratum));
     UTI_TimevalNetworkToHost(&reply.data.tracking.ref_time, &ref_time);
     ref_time_tm = *gmtime((time_t *)&ref_time.tv_sec);
     printf("Ref time (UTC)  : %s", asctime(&ref_time_tm));
@@ -1930,6 +1949,7 @@ process_cmd_tracking(char *line)
     printf("Root delay      : %.6f seconds\n", root_delay);
     printf("Root dispersion : %.6f seconds\n", root_dispersion);
     printf("Update interval : %.1f seconds\n", last_update_interval);
+    printf("Leap status     : %s\n", leap_status);
     return 1;
   }
   return 0;
index 0755a47807c4ce08f62365b807ab96f15f7a392c..f9d04c8d638154c9bfb2be9481918873dcfdad03 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -1382,7 +1382,8 @@ handle_tracking(CMD_Request *rx_message, CMD_Reply *tx_message)
   tx_message->reply  = htons(RPY_TRACKING);
   tx_message->data.tracking.ref_id = htonl(rpt.ref_id);
   UTI_IPHostToNetwork(&rpt.ip_addr, &tx_message->data.tracking.ip_addr);
-  tx_message->data.tracking.stratum = htonl(rpt.stratum);
+  tx_message->data.tracking.stratum = htons(rpt.stratum);
+  tx_message->data.tracking.leap_status = htons(rpt.leap_status);
   UTI_TimevalHostToNetwork(&rpt.ref_time, &tx_message->data.tracking.ref_time);
   tx_message->data.tracking.current_correction = UTI_FloatHostToNetwork(rpt.current_correction);
   tx_message->data.tracking.last_offset = UTI_FloatHostToNetwork(rpt.last_offset);
index 0310d208bb3c7bda37aaae8c5a722d6891bd9b5c..1ef3fa68a48e62c4e313e206de2db6e5edd0af17 100644 (file)
@@ -192,7 +192,7 @@ REF_Initialise(void)
   }
 
   logfileid = CNF_GetLogTracking() ? LOG_FileOpen("tracking",
-      "   Date (UTC) Time     IP Address   St   Freq ppm   Skew ppm     Offset")
+      "   Date (UTC) Time     IP Address   St   Freq ppm   Skew ppm     Offset L")
     : -1;
 
   max_update_skew = fabs(CNF_GetMaxUpdateSkew()) * 1.0e-6;
@@ -634,11 +634,12 @@ update_leap_status(NTP_Leap leap, time_t now)
 /* ================================================== */
 
 static void
-write_log(struct timeval *ref_time, char *ref, int stratum, double freq, double skew, double offset)
+write_log(struct timeval *ref_time, char *ref, int stratum, NTP_Leap leap, double freq, double skew, double offset)
 {
+  const char leap_codes[4] = {'N', '+', '-', '?'};
   if (logfileid != -1) {
-    LOG_FileWrite(logfileid, "%s %-15s %2d %10.3f %10.3f %10.3e",
-            UTI_TimeToLogForm(ref_time->tv_sec), ref, stratum, freq, skew, offset);
+    LOG_FileWrite(logfileid, "%s %-15s %2d %10.3f %10.3f %10.3e %1c",
+            UTI_TimeToLogForm(ref_time->tv_sec), ref, stratum, freq, skew, offset, leap_codes[leap]);
   }
 }
 
@@ -797,6 +798,7 @@ REF_SetReference(int stratum,
   write_log(&now,
             our_ref_ip.family != IPADDR_UNSPEC ? UTI_IPToString(&our_ref_ip) : UTI_RefidToString(our_ref_id),
             our_stratum,
+            our_leap_status,
             abs_freq_ppm,
             1.0e6*our_skew,
             our_offset);
@@ -864,6 +866,7 @@ REF_SetManualReference
   write_log(ref_time,
             "127.127.1.1",
             our_stratum,
+            our_leap_status,
             abs_freq_ppm,
             1.0e6*our_skew,
             offset);
@@ -889,16 +892,16 @@ REF_SetUnsynchronised(void)
     schedule_fb_drift(&now);
   }
 
+  update_leap_status(LEAP_Unsynchronised, 0);
+  are_we_synchronised = 0;
+
   write_log(&now,
             "0.0.0.0",
             0,
+            our_leap_status,
             LCL_ReadAbsoluteFrequency(),
             1.0e6*our_skew,
             0.0);
-
-  are_we_synchronised = 0;
-
-  update_leap_status(LEAP_Unsynchronised, 0);
 }
 
 /* ================================================== */
@@ -1041,6 +1044,7 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
   rep->ref_id = 0;
   rep->ip_addr.family = IPADDR_UNSPEC;
   rep->stratum = 0;
+  rep->leap_status = our_leap_status;
   rep->ref_time.tv_sec = 0;
   rep->ref_time.tv_usec = 0;
   rep->current_correction = correction;
index 4322a9c46ce62fa745bd2fe29404ba60a9975d57..646210668c8e3441e1ca0d1f39a20840cc43ccaa 100644 (file)
--- a/reports.h
+++ b/reports.h
@@ -51,6 +51,7 @@ typedef struct {
   uint32_t ref_id;
   IPAddr ip_addr;
   unsigned long stratum;
+  unsigned long leap_status;
   struct timeval ref_time;
   double current_correction;
   double last_offset;