[Git][NTPsec/ntpsec][master] Add msg for previous errors/warn when new log file

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Mon Oct 9 11:05:49 UTC 2023



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
98e5fe4c by Hal Murray at 2023-10-09T04:00:06-07:00
Add msg for previous errors/warn when new log file

This lets you know there were troubles parsing the config file.

- - - - -


1 changed file:

- libntp/msyslog.c


Changes:

=====================================
libntp/msyslog.c
=====================================
@@ -30,6 +30,14 @@ static char *	syslog_abs_fname;
 
 int		debug;
 
+/* Counters */
+struct log_counters {   /* LOG_EMERG, LOG_ALERT, LOG_CRIT not used */
+  uint64_t errors;      /* LOG_ERR */
+  uint64_t warnings;    /* LOG_WARNING */
+  uint64_t others;      /* LOG_NOTICE, LOG_INFO, and LOG_DEBUG */
+};
+struct log_counters log_cnt;
+
 /* libntp default ntp_syslogmask is all bits lit */
 #define INIT_NTP_SYSLOGMASK	~(uint32_t)0
 uint32_t ntp_syslogmask = INIT_NTP_SYSLOGMASK;
@@ -185,6 +193,22 @@ msyslog(
 	char	buf[1024];
 	va_list	ap;
 
+	switch (level) {
+		case LOG_ERR:
+			log_cnt.errors++;
+			break;
+		case LOG_WARNING:
+			log_cnt.warnings++;
+			break;
+		case LOG_NOTICE:	/* FALLTHROUGH */
+		case LOG_INFO:		/* FALLTHROUGH */
+		case LOG_DEBUG:
+			log_cnt.others++;
+			break;
+		default:
+			break;
+	}
+
 	va_start(ap, fmt);
 	vsnprintf(buf, sizeof(buf), fmt, ap);
 	va_end(ap);
@@ -360,6 +384,17 @@ change_logfile(
 	}
 	syslogit = false;
 
+	/* This leaves something in the log file if you have errors
+	 * parsing ntp.conf and you switch to a log file.
+	 * Maybe this should happen only during initialization.
+	 *   two places: commmand line and ntp.conf
+	 */ 
+	if (0<log_cnt.errors || 0<log_cnt.warnings) {
+		msyslog(log_cnt.errors? LOG_ERR: LOG_WARNING,
+		"LOG: %lu errors and %lu warnings in previous log file(s)",
+		(unsigned long)log_cnt.errors, (unsigned long)log_cnt.warnings);
+	}
+
 	return 0;
 }
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/98e5fe4c5ddcc80cf86f39fd9f898cd487d5d1ef

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/98e5fe4c5ddcc80cf86f39fd9f898cd487d5d1ef
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20231009/acf621f8/attachment-0001.htm>


More information about the vc mailing list