[Git][NTPsec/ntpsec][master] 2 commits: Add logging to authreadkeys, handy for debugging

Hal Murray gitlab at mg.gitlab.com
Tue Dec 22 09:50:22 UTC 2015


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
3730f21e by Hal Murray at 2015-12-22T01:48:22Z
Add logging to authreadkeys, handy for debugging

- - - - -
9fac4ea4 by Hal Murray at 2015-12-22T01:49:14Z
Switch to log file (from ntp.conf) earlier

So some error messages are easier to find.

- - - - -


2 changed files:

- libntp/authreadkeys.c
- ntpd/ntp_config.c


Changes:

=====================================
libntp/authreadkeys.c
=====================================
--- a/libntp/authreadkeys.c
+++ b/libntp/authreadkeys.c
@@ -79,6 +79,7 @@ authreadkeys(
 	uint8_t	keystr[32];		/* Bug 2537 */
 	size_t	len;
 	size_t	j;
+	int	keys = 0;
 
 	/*
 	 * Open file.  Complain and return if it can't be opened.
@@ -90,6 +91,7 @@ authreadkeys(
 		return false;
 	}
 	INIT_SSL();
+msyslog(LOG_ERR, "authreadkeys: reading %s", file);
 
 	/*
 	 * Remove all existing keys
@@ -177,6 +179,7 @@ authreadkeys(
 		len = strlen(token);
 		if (len <= 20) {	/* Bug 2537 */
 			MD5auth_setkey(keyno, keytype, (uint8_t *)token, len);
+			keys++;
 		} else {
 			char	hex[] = "0123456789abcdef";
 			uint8_t	temp;
@@ -200,8 +203,10 @@ authreadkeys(
 				continue;
 			}
 			MD5auth_setkey(keyno, keytype, keystr, jlim / 2);
+			keys++;
 		}
 	}
 	fclose(fp);
+msyslog(LOG_ERR, "authreadkeys: added %d keys", keys);
 	return true;
 }


=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -276,6 +276,7 @@ static void config_rlimit(config_tree *);
 static void config_system_opts(config_tree *);
 static void config_tinker(config_tree *);
 static void config_tos(config_tree *);
+static void config_logfile(config_tree *);
 static void config_vars(config_tree *);
 
 #ifdef SIM
@@ -3422,6 +3423,33 @@ free_config_fudge(
 #endif	/* FREE_CFG_T */
 
 
+/* Clone of config_vars that only does log file. */
+static void
+config_logfile(
+	config_tree *ptree
+	)
+{
+	attr_val *curr_var;
+
+	curr_var = HEAD_PFIFO(ptree->vars);
+	for (; curr_var != NULL; curr_var = curr_var->link) {
+		/* Determine which variable to set and set it */
+		switch (curr_var->attr) {
+
+		case T_Logfile:
+			if (-1 == change_logfile(curr_var->value.s, true))
+				msyslog(LOG_ERR,
+					"Cannot open logfile %s: %m",
+					curr_var->value.s);
+			break;
+
+		default:
+			break;
+		}
+	}
+}
+
+
 static void
 config_vars(
 	config_tree *ptree
@@ -3481,10 +3509,7 @@ config_vars(
 			break;
 
 		case T_Logfile:
-			if (-1 == change_logfile(curr_var->value.s, true))
-				msyslog(LOG_ERR,
-					"Cannot open logfile %s: %m",
-					curr_var->value.s);
+			/* processed in config_logfile */
 			break;
 
 		case T_Saveconfigdir:
@@ -4262,6 +4287,11 @@ config_ntpd(
 	bool input_from_files
 	)
 {
+
+/* Do this early so most errors go to new log file */
+/* Command line arg is earlier. */
+	config_logfile(ptree);
+
 	config_nic_rules(ptree, input_from_files);
 	config_monitor(ptree);
 	config_auth(ptree);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/036c281ac07d8f137112ad740f96a21f635831d1...9fac4ea48fdbcacb2d6ce53f0491446d2414af55
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151222/b5fcdc19/attachment.html>


More information about the vc mailing list