[Git][NTPsec/ntpsec][master] Replay - split config file name computation from parsing...

Eric S. Raymond gitlab at mg.gitlab.com
Thu Dec 31 12:04:14 UTC 2015


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
2598c8a8 by Eric S. Raymond at 2015-12-31T07:03:11Z
Replay - split config file name computation from parsing...

...so that logging can get done in the right order.

- - - - -


3 changed files:

- include/ntpd.h
- ntpd/ntp_config.c
- ntpd/ntp_intercept.c


Changes:

=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -58,6 +58,7 @@ extern	char	*keysdir;	/* crypto keys and leaptable directory */
 extern	char *	saveconfigdir;	/* ntpq saveconfig output directory */
 
 extern	const char	*getconfig	(const char *);
+extern	void	readconfig(const char *);
 extern	void	ctl_clr_stats	(void);
 extern	bool	ctlclrtrap	(sockaddr_u *, struct interface *, int);
 extern	u_short ctlpeerstatus	(struct peer *);


=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -4402,12 +4402,11 @@ config_remotely(
 
 
 /*
- * getconfig() - process startup configuration file e.g /etc/ntp.conf
+ * getconfig() - return name of configuration file e.g /etc/ntp.conf
  */
 const char *
 getconfig(const char *explicit_config)
 {
-	char	line[256];
 	const char *config_file;
 
 #ifndef SYS_WINNT
@@ -4442,6 +4441,20 @@ getconfig(const char *explicit_config)
 	    config_file = explicit_config;
 	}
 
+#ifdef SYS_WINNT
+	if (access(config_file, R_OK) != 0)
+	    config_file = alt_config_file;
+#endif /* SYS_WINNT */
+
+	return config_file;
+}
+
+/*
+ * readconfig() - process startup configuration file
+ */
+void readconfig(const char *config_file)
+{
+	char	line[256];
 	/*
 	 * install a non default variable with this daemon version
 	 */
@@ -4468,22 +4481,7 @@ getconfig(const char *explicit_config)
 		if (!saveconfigquit && intercept_get_mode() != replay)
 			io_open_sockets();
 
-		return NULL;
-#else
-		/* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */
-
-		if (!lex_init_stack(alt_config_file, "r"))  {
-			/*
-			 * Broadcast clients can sometimes run without
-			 * a configuration file.
-			 */
-			msyslog(LOG_INFO, "getconfig: Couldn't open <%s>: %m", alt_config_file);
-			if (!saveconfigquit && intercept_get_mode() != replay)
-				io_open_sockets();
-
-			return NULL;
-		}
-		cfgt.source.value.s = estrdup(alt_config_file);
+		return;
 #endif	/* SYS_WINNT */
 	} else
 		cfgt.source.value.s = estrdup(config_file);
@@ -4510,8 +4508,6 @@ getconfig(const char *explicit_config)
 	if (config_netinfo)
 		free_netinfo_config(config_netinfo);
 #endif /* HAVE_NETINFO_NI_H */
-
-	return config_file;
 }
 
 


=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -110,7 +110,6 @@ static intercept_mode mode = none;
 
 static char linebuf[256];
 static int lineno;
-static double saved_drift;
 
 intercept_mode intercept_get_mode(void)
 {
@@ -312,7 +311,7 @@ void intercept_getconfig(const char *configfile)
 	get_operation("startconfig");
 	snprintf(tempfile, sizeof(tempfile), ".fake_ntp_config_%d", getpid());
 	file_replay(configfile, "endconfig", tempfile);
-	getconfig(tempfile);
+	readconfig(getconfig(tempfile));
 	unlink(tempfile);
     } else {
 	/* this can be null if the default config doesn't exist */
@@ -321,13 +320,7 @@ void intercept_getconfig(const char *configfile)
 	if (configfile != NULL && mode == capture)
 	    pump(configfile, "startconfig\n", "endconfig\n", stdout);
 
-	/*
-	 * Has to be done here because intercept_drift_read() is called from
-	 * inside the config parser - otherwise, things get emitted in the
-	 * wrong order.
-	 */
-	if (mode == capture)
-	    printf("drift-read %.3f\n", saved_drift);
+	readconfig(configfile);
     }
 }
 
@@ -432,8 +425,9 @@ bool intercept_drift_read(const char *drift_file, double *drift)
 	}
 	fclose(fp);
 
-	/* capture write has to be done in the config intercwept */
-	saved_drift = *drift;
+	if (mode == capture)
+	    printf("drift-read %.3f\n", *drift);
+
     }
 
     return true;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/2598c8a886feaf40c2a07cc4f77d7968ee31ea14
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151231/1ec08109/attachment.html>


More information about the vc mailing list