<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>Eric S. Raymond pushed to branch master at <a href="https://gitlab.com/NTPsec/ntpsec">NTPsec / ntpsec</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.com/NTPsec/ntpsec/commit/0eb7e063e1b502c4eaf22ed86d959b4f3a5fcd5c">0eb7e063</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-12T08:16:12Z</i>
</div>
<pre class='commit-message'>Still more replay implementation.</pre>
</li>
</ul>
<h4>1 changed file:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
ntpd/ntp_intercept.c
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/NTPsec/ntpsec/commit/0eb7e063e1b502c4eaf22ed86d959b4f3a5fcd5c#diff-0'>
<strong>
ntpd/ntp_intercept.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntp_intercept.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntp_intercept.c
</span><span style="color: #aaaaaa">@@ -6,9 +6,9 @@ Think of ntpd as a complex finite-state machine for transforming a
</span> stream of input events to output events.  Events are of the
 following kinds:
 
<span style="color: #000000;background-color: #ffdddd">-1. Startup or termination.
</span><span style="color: #000000;background-color: #ddffdd">+1. Startup, capuring command-line switches.
</span> 
<span style="color: #000000;background-color: #ffdddd">-2. Configuration read (including option state).
</span><span style="color: #000000;background-color: #ddffdd">+2. Configuration read.
</span> 
 3. Time reports from reference clocks.
 
<span style="color: #aaaaaa">@@ -74,10 +74,7 @@ no mismatches.
</span> 
 == Limitations ==
 
<span style="color: #000000;background-color: #ffdddd">-Replay mode has to not require root privileges and not actually change
-the timekeeping state of the machine.  Therefore it mocks the state of the
-system clock with static storage.  Bug: the state of the PLL is not yet
-mocked.
</span><span style="color: #000000;background-color: #ddffdd">+Reference-clock eventare not yet intercepted.
</span> 
 *****************************************************************************/
 
<span style="color: #aaaaaa">@@ -334,7 +331,7 @@ bool intercept_drift_read(const char *drift_file, double *drift)
</span>    * This could cause an obscure bug in replay if drift 
         * ever requires 53 bits of precision as opposed to 24
         * (and that's assuming IEEE-754, otherwise things could
<span style="color: #000000;background-color: #ffdddd">-         * get .
</span><span style="color: #000000;background-color: #ddffdd">+    * get hairier).
</span>    */ 
        if (sscanf(linebuf, "drift-read %f'", &df) != 1) {
            fprintf(stderr, "ntpd: garbled drift-read format, line %d\n",lineno);
<span style="color: #aaaaaa">@@ -370,11 +367,25 @@ bool intercept_drift_read(const char *drift_file, double *drift)
</span> 
 void intercept_drift_write(char *driftfile, double drift)
 {
<span style="color: #000000;background-color: #ffdddd">-    if (mode != none)
-       printf("drift-write %.3f\n", drift);
-
-    if (mode != replay)
-    {
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == replay) {
+       /*
+        * We don't want to actually mes with the system's timekeeping in 
+        * replay mode, so just check that we're writing out the same drift. 
+        */
+       float df;
+       get_operation("drift-write");
+       /* See the comment of drift-read chwxcking. */ 
+       if (sscanf(linebuf, "drift-write %f'", &df) != 1) {
+           fprintf(stderr, "ntpd: garbled drift-write format, line %d\n",lineno);
+           exit(1);
+       }
+       /* beware spurious failures here due to float imprecisiion */ 
+       if (df != drift) {
+           fprintf(stderr, "ntpd: expected drift %f but saw %f, line %d\n",
+                   drift, df, lineno);
+           exit(1);
+       }
+    } else {
</span>   int fd;
        char tmpfile[PATH_MAX], driftcopy[PATH_MAX];
        char driftval[32];
<span style="color: #aaaaaa">@@ -401,18 +412,51 @@ void intercept_drift_write(char *driftfile, double drift)
</span>       msyslog(LOG_WARNING,
                    "Unable to rename temp drift file %s to %s, %m",
                    tmpfile, driftfile);
<span style="color: #000000;background-color: #ddffdd">+
+       if (mode == capture)
+           printf("drift-write %.3f\n", drift);
</span>     }
 }
 
 int intercept_adjtime(const struct timeval *ntv, struct timeval *otv)
 /* old-fashioned BSD call for systems with no PLL */
 {
<span style="color: #000000;background-color: #ffdddd">-    printf("adjtime %ld %ld %ld %ld",
-          (long)ntv->tv_sec, (long)ntv->tv_usec, (long)ntv->tv_sec, (long)ntv->tv_usec);
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == replay) {
+       struct timeval rntv, rotv;
+       get_operation("adjtime");
+       /* bletch - likely to foo up on 32-bit machines */
+       if (sscanf(linebuf, "adjtime %ld %ld %ld %ld",
+                  &rntv.tv_sec, &rntv.tv_usec,
+                  &rotv.tv_sec, &rotv.tv_usec) != 4)
+       {
+           fprintf(stderr, "ntpd: garbled adjtime format, line %d\n", lineno);
+           exit(1);
+       }
+       if (ntv->tv_sec != rntv.tv_sec
+           || ntv->tv_usec != rntv.tv_usec
+           || otv->tv_sec != rotv.tv_sec
+           || otv->tv_usec != rotv.tv_usec)
+       {
+           fprintf(stderr, "ntpd: adjtime expected %ld.%ld/%ld.%ld but saw %ld.%ld/%ld.%ld, line %d\n",
+                   (long)rntv.tv_sec,
+                   (long)rntv.tv_usec,
+                   (long)rotv.tv_sec,
+                   (long)rotv.tv_usec,  
+                   (long)ntv->tv_sec,
+                   (long)ntv->tv_usec,
+                   (long)otv->tv_sec,
+                   (long)otv->tv_usec,  
+                   lineno);
+           exit(1);
+       }
+    } else {
+       if (mode == capture)
+           printf("adjtime %ld %ld %ld %ld",
+                  (long)ntv->tv_sec, (long)ntv->tv_usec,
+                  (long)otv->tv_sec, (long)otv->tv_usec);
</span> 
<span style="color: #000000;background-color: #ffdddd">-    if (mode != replay)
</span>   return adjtime(ntv, otv);
<span style="color: #000000;background-color: #ffdddd">-
</span><span style="color: #000000;background-color: #ddffdd">+    }
</span>     return 0;
 }
 
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>

<br>
<a href="https://gitlab.com/NTPsec/ntpsec/commit/0eb7e063e1b502c4eaf22ed86d959b4f3a5fcd5c">View it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://gitlab.com/NTPsec/ntpsec/commit/0eb7e063e1b502c4eaf22ed86d959b4f3a5fcd5c"}}</script>
</p>
</div>
</body>
</html>