<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/ca794df3bac397df30528672b2a2b6142ce400d0">ca794df3</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-11T15:52:51Z</i>
</div>
<pre class='commit-message'>More replay implementation.

Fixes a bug introduced by my previus commit "For TESTFRAME, properly intercept
calls to set time of day." that would have messed up time stepping.</pre>
</li>
<li>
<strong><a href="https://gitlab.com/NTPsec/ntpsec/commit/f62864046ae8da21aeddb4d79827f213452a0567">f6286404</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-12T06:31:30Z</i>
</div>
<pre class='commit-message'>Yet more replay implementation.</pre>
</li>
</ul>
<h4>2 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
ntpd/ntp_intercept.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
ntpd/ntp_intercept.h
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/NTPsec/ntpsec/compare/9ddcb323e89f0250d82441365f0618c56cab421e...f62864046ae8da21aeddb4d79827f213452a0567#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">@@ -111,10 +111,8 @@ mocked.
</span> 
 static intercept_mode mode = none;
 
<span style="color: #000000;background-color: #ffdddd">-/* mock the clock state */
-static l_fp replay_time;
-
</span> static char linebuf[256];
<span style="color: #000000;background-color: #ddffdd">+static int lineno;
</span> 
 intercept_mode intercept_get_mode(void)
 {
<span style="color: #aaaaaa">@@ -137,6 +135,8 @@ static void get_operation(const char *expect)
</span>     {
        char *in = fgets(linebuf, sizeof(linebuf), stdin);
 
<span style="color: #000000;background-color: #ddffdd">+        ++lineno;
+
</span>   if (in == NULL) {
            fputs("ntpd: replay failed, unexpected EOF\n", stderr);
            exit(1);
<span style="color: #aaaaaa">@@ -246,16 +246,6 @@ void intercept_getconfig(const char *configfile)
</span>     }
 }
 
<span style="color: #000000;background-color: #ffdddd">-void intercept_log(const char *fmt, ...)
-{
-    if (mode == capture) {
-       va_list ap;
-       va_start(ap, fmt);
-       vfprintf(stdout, fmt, ap);
-       va_end(ap);
-    }
-}
-
</span> /*
  * An lfp used as a full date has an an unsigned seconds part.
  * Invert this with atolfp().
<span style="color: #aaaaaa">@@ -267,56 +257,113 @@ void intercept_get_systime(const char *legend, l_fp *now)
</span>     struct timespec ts;   /* seconds and nanoseconds */
 
     if (mode == replay) {
<span style="color: #000000;background-color: #ffdddd">-        *now = replay_time;
</span><span style="color: #000000;background-color: #ddffdd">+   int sec, subsec;
+       char expecting[BUFSIZ];
+       get_operation("systime");
+       if (sscanf(linebuf, "systime %s %d.%d", expecting, &sec, &subsec) != 3) {
+           fprintf(stderr, "ntpd: garbled systime format, line %d\n", lineno);
+           exit(1);
+       }
+       else if (strcmp(legend, expecting) == 0) {
+           fprintf(stderr, "ntpd: expected systime %s on line %d\n",
+                   expecting, lineno);
+           exit(1);
+       }
+       ts.tv_sec = sec;
+       ts.tv_nsec = subsec;
+       normalize_time(ts, 0, now);
</span>     } else {
        get_ostime(&ts);
        normalize_time(ts, sys_fuzz > 0.0 ? ntp_random() : 0, now);
<span style="color: #000000;background-color: #ffdddd">-    }
-
-    if (mode != none)
-       printf("systime %s %s\n", legend, lfpdump(now));
</span><span style="color: #000000;background-color: #ddffdd">+   if (mode == capture)
+           printf("systime %s %s\n", legend, lfpdump(now));
</span> 
<span style="color: #000000;background-color: #ddffdd">+    }
</span> }
 
 long intercept_ntp_random(const char *legend)
 {
<span style="color: #000000;background-color: #ffdddd">-    long rand = ntp_random();
</span><span style="color: #000000;background-color: #ddffdd">+    long roll;
</span> 
<span style="color: #000000;background-color: #ffdddd">-    /* FIXME: replay logic goes here */
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == replay) {
+       char expecting[BUFSIZ];
+       /*
+        * Presently we're only using this as a check on the call sequence,
+        * as all the environment-altering functions that call ntp_random()
+        * are themselves intercepted.
+        */
+       if (sscanf(linebuf, "random %s %ld", expecting, &roll) != 2) {
+           fprintf(stderr, "ntpd: garbled random format, line %d\n", lineno);
+           exit(1);
+       }
+       else if (strcmp(legend, expecting) == 0) {
+           fprintf(stderr, "ntpd: expected random %s on line %d\n",
+                   expecting, lineno);
+           exit(1);
+       }
+       return roll;
+    } else {
+       roll = ntp_random();
</span> 
<span style="color: #000000;background-color: #ffdddd">-    if (mode != none)
-       printf("random %s %ld\n", legend, rand);
</span><span style="color: #000000;background-color: #ddffdd">+   if (mode == capture)
+           printf("random %s %ld\n", legend, roll);
+    }
</span> 
<span style="color: #000000;background-color: #ffdddd">-    return rand;
</span><span style="color: #000000;background-color: #ddffdd">+    return roll;
</span> }
 
 void intercept_timer(void)
 {
<span style="color: #000000;background-color: #ffdddd">-    if (mode != none)
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == capture)
</span>   printf("timer\n");
<span style="color: #000000;background-color: #ddffdd">+    else if (mode == replay)
+       /* probably is not necessary to record this... */
+       get_operation("timer");
</span>     timer();
 }
 
 bool intercept_drift_read(const char *drift_file, double *drift)
 {
<span style="color: #000000;background-color: #ffdddd">-    FILE *fp;
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == replay) {
+       float df;
+       get_operation("drift_read");
+       if (strstr(linebuf, "false") != NULL)
+           return false;
+       /*
+        * Weirdly, sscanf has no format for reading doubles.
+        * 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
+        * get .
+        */ 
+       if (sscanf(linebuf, "drift-read %f'", &df) != 1) {
+           fprintf(stderr, "ntpd: garbled drift-read format, line %d\n",lineno);
+           exit(1);
+       }
+       *drift = df;
+    } else {
+       FILE *fp;
</span> 
<span style="color: #000000;background-color: #ffdddd">-    if (mode != replay) {
-       if ((fp = fopen(drift_file, "r")) == NULL)
</span><span style="color: #000000;background-color: #ddffdd">+   if ((fp = fopen(drift_file, "r")) == NULL) {
+           if (mode == capture)
+               printf("drift-read false\n");
</span>       return false;
<span style="color: #000000;background-color: #ddffdd">+        }
</span> 
        if (fscanf(fp, "%lf", drift) != 1) {
            msyslog(LOG_ERR,
                    "format error frequency file %s",
                    drift_file);
            fclose(fp);
<span style="color: #000000;background-color: #ddffdd">+            if (mode == capture)
+               printf("drift-read false\n");
</span>       return false;
        }
        fclose(fp);
<span style="color: #000000;background-color: #ffdddd">-    }
</span> 
<span style="color: #000000;background-color: #ffdddd">-    if (mode != none)
-       printf("drift-read %.3f\n", *drift);
</span><span style="color: #000000;background-color: #ddffdd">+   if (mode == capture)
+           printf("drift-read %.3f\n", *drift);
+    }
</span> 
     return true;
 }
<span style="color: #aaaaaa">@@ -407,13 +454,15 @@ int intercept_ntp_adjtime(struct timex *tx)
</span> 
 int intercept_set_tod(struct timespec *tvs)
 {
<span style="color: #000000;background-color: #ffdddd">-    if (mode != none)
-       printf("set_tod %ld %ld\n", (long)tvs->tv_sec, tvs->tv_nsec);
-
-    if (mode == replay)
</span><span style="color: #000000;background-color: #ddffdd">+    if (mode == replay) {
+       get_operation("set_tod");
+       /* FIXME: more replay logic goes here */
+    }
+    else {
+       if (mode == capture)
+           printf("set_tod %ld %ld\n", (long)tvs->tv_sec, tvs->tv_nsec);
</span>   return ntp_set_tod(tvs);
<span style="color: #000000;background-color: #ffdddd">-
-    normalize_time(*tvs, 9, &replay_time);
</span><span style="color: #000000;background-color: #ddffdd">+    }
</span>     return 0;
 }
 
<span style="color: #aaaaaa">@@ -521,7 +570,7 @@ void intercept_exit(int sig)
</span>     if (mode != none)
        printf("finish %d\n", sig);
 
<span style="color: #000000;background-color: #ffdddd">-    exit(sig);
</span><span style="color: #000000;background-color: #ddffdd">+    exit(0);
</span> }
 
 /* end */
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://gitlab.com/NTPsec/ntpsec/compare/9ddcb323e89f0250d82441365f0618c56cab421e...f62864046ae8da21aeddb4d79827f213452a0567#diff-1'>
<strong>
ntpd/ntp_intercept.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntp_intercept.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntp_intercept.h
</span><span style="color: #aaaaaa">@@ -11,20 +11,11 @@
</span> # include <sys/timex.h>
 #endif
 
<span style="color: #000000;background-color: #ffdddd">-/* Macro for declaring function with printf-like arguments. */
-# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-#define PRINTF_FUNC(format_index, arg_index) \
-    __attribute__((__format__(__printf__, format_index, arg_index)))
-# else
-#define PRINTF_FUNC(format_index, arg_indx)
-#endif
-
</span> typedef enum {none, capture, replay} intercept_mode;
 
 intercept_mode intercept_get_mode(void);
 void intercept_set_mode(intercept_mode);
 
<span style="color: #000000;background-color: #ffdddd">-PRINTF_FUNC(1, 2) void intercept_log(const char *, ...);
</span> void intercept_argparse(int *, char ***);
 void intercept_getconfig(const char *);
 void intercept_get_systime(const char *, l_fp *);
</code></pre>

<br>
</li>

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

<br>
<a href="https://gitlab.com/NTPsec/ntpsec/compare/9ddcb323e89f0250d82441365f0618c56cab421e...f62864046ae8da21aeddb4d79827f213452a0567">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.

</p>
</div>
</body>
</html>