[Git][NTPsec/ntpsec][master] TESTFRAME progress - intercept calls to read the leapsecond file.
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Nov 29 19:14:53 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
5f5159fe by Eric S. Raymond at 2015-11-29T14:04:12Z
TESTFRAME progress - intercept calls to read the leapsecond file.
Required moving it from libntp/ to ntpd/, otherwice ntp_leapsec.h won't
be visible. This is better factoring, anyway.
- - - - -
5 changed files:
- include/ntp_intercept.h
- libntp/wscript
- libntp/intercept.c → ntpd/ntp_intercept.c
- ntpd/ntp_util.c
- ntpd/wscript
Changes:
=====================================
include/ntp_intercept.h
=====================================
--- a/include/ntp_intercept.h
+++ b/include/ntp_intercept.h
@@ -2,6 +2,10 @@
* ntp_intercept.h - intercept/replay support for environment calls
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#ifdef HAVE_SYS_TIMEX_H
# include <sys/time.h> /* prerequisite on NetBSD */
# include <sys/timex.h>
@@ -33,5 +37,7 @@ void intercept_drift_write(char *, double);
#ifdef HAVE_KERNEL_PLL
int intercept_kernel_pll_adjtime(struct timex *);
#endif
+extern bool intercept_leapsec_load_file(const char * fname, struct stat * sb,
+ bool force, bool logall);
/* end */
=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -20,7 +20,6 @@ def build(ctx):
"hextolfp.c",
"humandate.c",
"icom.c",
- "intercept.c",
"iosignal.c",
"lib_strbuf.c",
"machines.c",
=====================================
libntp/intercept.c → ntpd/ntp_intercept.c
=====================================
--- a/libntp/intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -1,6 +1,6 @@
/*****************************************************************************
-intercept.c - capture and replay logic for NTP environment calls
+ntp_intercept.c - capture and replay logic for NTP environment calls
Think of ntpd as a complex finite-state machine for transforming a
stream of input events to output events. Events are of the
@@ -22,7 +22,7 @@ following kinds:
8. Calls to adjtime to set the system clock.
-9. Read of the system leapsecond file. (TODO)
+9. Read of the system leapsecond file.
10. Packets incoming from NTP daemons. (TODO)
@@ -98,6 +98,7 @@ no mismatches.
#include "ntp_intercept.h"
#include "ntp_fp.h"
#include "ntp_syscall.h"
+#include "ntp_leapsec.h"
static intercept_mode mode = none;
@@ -286,6 +287,36 @@ int intercept_kernel_pll_adjtime(struct timex *tx)
}
#endif
+bool
+intercept_leapsec_load_file(
+ const char * fname,
+ struct stat * sb_old,
+ bool force,
+ bool logall)
+{
+ bool loaded;
+
+ if (mode != replay)
+ loaded = leapsec_load_file(fname, sb_old, force, logall);
+
+ if (mode == capture) {
+ FILE *fp = fopen(fname, "r");
+ if (fp != NULL) {
+ int c;
+
+ fputs("startleapsec\n", stdout);
+ while ((c = fgetc(fp)) != EOF)
+ putchar(c);
+ fclose(fp);
+ fputs("endleapsec\n", stdout);
+ }
+ }
+
+ /* FIXME: replay logic goes here */
+
+ return loaded;
+}
+
void intercept_sendpkt(const char *legend,
sockaddr_u *dest, struct interface *ep, int ttl,
struct pkt *pkt, int len)
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -349,7 +349,7 @@ stats_config(
leapfile_name = erealloc(leapfile_name, len + 1);
memcpy(leapfile_name, value, len + 1);
- if (leapsec_load_file(
+ if (intercept_leapsec_load_file(
leapfile_name, &leapfile_stat, true, true))
{
leap_signature_t lsig;
@@ -745,7 +745,7 @@ check_leap_file(
return;
/* try to load leapfile, force it if no leapfile loaded yet */
- if (leapsec_load_file(
+ if (intercept_leapsec_load_file(
leapfile_name, &leapfile_stat,
!have_leapfile, is_daily_check))
have_leapfile = true;
=====================================
ntpd/wscript
=====================================
--- a/ntpd/wscript
+++ b/ntpd/wscript
@@ -55,6 +55,7 @@ def build(ctx):
"ntp_control.c",
"ntp_crypto.c",
"ntp_filegen.c",
+ "ntp_intercept.c",
"ntp_leapsec.c",
"ntp_loopfilter.c",
"ntp_monitor.c",
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5f5159fed7317af06adea0c93982360a5547dd7e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151129/7c98db2b/attachment.html>
More information about the vc
mailing list