[Git][NTPsec/ntpsec][master] 9 commits: libisc: hardcode library_fatal_error() handler, remove isc_error_setfatal

Gary E. Miller gitlab at mg.gitlab.com
Tue Jun 6 03:47:42 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
b65c3d67 by Gary E. Miller at 2017-06-05T18:49:42-07:00
libisc: hardcode library_fatal_error() handler, remove isc_error_setfatal

ntpsec only used library_fatal_error(), so just hard code it.  The
old code tried to prevent recursion, but in this case could not
happen.

- - - - -
7267ebe5 by Gary E. Miller at 2017-06-05T18:59:34-07:00
libisc: hardcode library_unexpected_error(), remove isc_error_setunexpected()

ntpsec only used library_unexpected_error(), so just hard code it.

- - - - -
68bbb6f2 by Gary E. Miller at 2017-06-05T19:04:27-07:00
libisc: remove unexpected_callback and fatal_callback

Another layer of useless indirection.

- - - - -
f5f69d52 by Gary E. Miller at 2017-06-05T20:11:35-07:00
libisc: remove another layer of indirection to library_fatal_error()

Also change abort() to exit(-4).  abort() is being flakey.

- - - - -
5dfc2c78 by Gary E. Miller at 2017-06-05T20:16:47-07:00
libisc: collase ISC_ERROR_RUNTIMECHECK() into RUNTIME_CHECK()

yet another level of indirection.

- - - - -
3cf71880 by Gary E. Miller at 2017-06-05T20:19:01-07:00
libisc: remove unused TIME_NOW().

- - - - -
e32d5523 by Gary E. Miller at 2017-06-05T20:22:37-07:00
libisc: remove unused RUNTIME_CHECK() and its friends.

Wow, a big circular rat's nest that was never used!

- - - - -
ef99fa7d by Gary E. Miller at 2017-06-05T20:26:33-07:00
libisc: remove unused ISC_UTIL_TRACEON macro

- - - - -
759eaded by Gary E. Miller at 2017-06-05T20:29:05-07:00
libisc: replace one UNUSED() with UN USED_ARG(), remove UNUSED().

- - - - -


6 changed files:

- devel/ifdex-ignores
- libisc/error.c
- libisc/ifiter_sysctl.c
- libisc/include/isc/error.h
- libisc/include/isc/util.h
- ntpd/ntpd.c


Changes:

=====================================
devel/ifdex-ignores
=====================================
--- a/devel/ifdex-ignores
+++ b/devel/ifdex-ignores
@@ -38,7 +38,6 @@ NTPD_PRIO		# Priority to set the daemon to
 DEBUG
 ISC_LIST_CHECKINIT	# Debugging flag
 USEBACKTRACE	        # Use backtrace code, set by --enable-debug-gdb
-ISC_UTIL_TRACEON	# Enables trace code in ISC service routines.
 DEBUG_PARSELIB		# Enable debugging in the parse library.
 NTP_DEBUG_LISTS		# Debug list handling
 DEBUG_PPS720		# Only in refclock_true.c


=====================================
libisc/error.c
=====================================
--- a/libisc/error.c
+++ b/libisc/error.c
@@ -12,80 +12,48 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "ntp_config.h"
+#include "ntp_syslog.h"
+
 #include "isc/error.h"
 
 /*% Default unexpected callback. */
-static void
-default_unexpected_callback(const char *, int, const char *, va_list)
-     ISC_FORMAT_PRINTF(3, 0);
-
-/*% Default fatal callback. */
-static void
-default_fatal_callback(const char *, int, const char *, va_list)
-     ISC_FORMAT_PRINTF(3, 0);
-
-/*% unexpected_callback */
-static isc_errorcallback_t unexpected_callback ISC_FORMAT_PRINTF(3, 0) \
-	 = default_unexpected_callback;
-static isc_errorcallback_t fatal_callback ISC_FORMAT_PRINTF(3, 0) \
-	 = default_fatal_callback;
-
-void
-isc_error_setunexpected(isc_errorcallback_t cb) {
-	if (cb == NULL)
-		unexpected_callback = default_unexpected_callback;
-	else
-		unexpected_callback = cb;
-}
-
-void
-isc_error_setfatal(isc_errorcallback_t cb) {
-	if (cb == NULL)
-		fatal_callback = default_fatal_callback;
-	else
-		fatal_callback = cb;
-}
+static void	library_unexpected_error(const char *, int,
+					 const char *, va_list)
+					ISC_FORMAT_PRINTF(3, 0);
 
 void
 isc_error_unexpected(const char *file, int line, const char *format, ...) {
 	va_list args;
 
 	va_start(args, format);
-	(unexpected_callback)(file, line, format, args);
+	library_unexpected_error(file, line, format, args);
 	va_end(args);
 }
 
-void
-isc_error_fatal(const char *file, int line, const char *format, ...) {
-	va_list args;
+/*
+ * library_unexpected_error - Handle non fatal errors from our libraries.
+ */
+#define MAX_UNEXPECTED_ERRORS 100
+static void
+library_unexpected_error(
+	const char *file,
+	int line,
+	const char *format,
+	va_list args
+	)
+{
+	char errbuf[256];
+	static int unexpected_error_cnt = 0;
 
-	va_start(args, format);
-	(fatal_callback)(file, line, format, args);
-	va_end(args);
-	abort();
-}
+	if (unexpected_error_cnt >= MAX_UNEXPECTED_ERRORS)
+		return;	/* avoid clutter in log */
 
-void
-isc_error_runtimecheck(const char *file, int line, const char *expression) {
-	isc_error_fatal(file, line, "RUNTIME_CHECK(%s) failed", expression);
-}
+	msyslog(LOG_ERR, "%s:%d: unexpected error:", file, line);
+	vsnprintf(errbuf, sizeof(errbuf), format, args);
+	msyslog(LOG_ERR, "%s", errbuf);
 
-static void
-default_unexpected_callback(const char *file, int line, const char *format,
-			    va_list args)
-{
-	fprintf(stderr, "%s:%d: ", file, line);
-	vfprintf(stderr, format, args);
-	fprintf(stderr, "\n");
-	fflush(stderr);
-}
+	if (++unexpected_error_cnt == MAX_UNEXPECTED_ERRORS)
+		msyslog(LOG_ERR, "Too many errors.  Shutting up.");
 
-static void
-default_fatal_callback(const char *file, int line, const char *format,
-		       va_list args)
-{
-	fprintf(stderr, "%s:%d: fatal error: ", file, line);
-	vfprintf(stderr, format, args);
-	fprintf(stderr, "\n");
-	fflush(stderr);
 }


=====================================
libisc/ifiter_sysctl.c
=====================================
--- a/libisc/ifiter_sysctl.c
+++ b/libisc/ifiter_sysctl.c
@@ -270,7 +270,7 @@ internal_next(isc_interfaceiter_t *iter) {
 
 static void
 internal_destroy(isc_interfaceiter_t *iter) {
-	UNUSED(iter); /* Unused. */
+	UNUSED_ARG(iter); /* Unused. */
 	/*
 	 * Do nothing.
 	 */


=====================================
libisc/include/isc/error.h
=====================================
--- a/libisc/include/isc/error.h
+++ b/libisc/include/isc/error.h
@@ -34,13 +34,4 @@ void
 isc_error_fatal(const char *, int, const char *, ...)
 ISC_FORMAT_PRINTF(3, 4) __attribute__	((__noreturn__));
 
-/*% runtimecheck error */
-void
-isc_error_runtimecheck(const char *, int, const char *)
-			__attribute__	((__noreturn__));
-
-#define ISC_ERROR_RUNTIMECHECK(cond) \
-	((void) ((cond) || \
-		 ((isc_error_runtimecheck)(__FILE__, __LINE__, #cond), 0)))
-
 #endif /* GUARD_ISC_ERROR_H */


=====================================
libisc/include/isc/util.h
=====================================
--- a/libisc/include/isc/util.h
+++ b/libisc/include/isc/util.h
@@ -20,36 +20,11 @@
  * ISC_ or isc_ to the name.
  */
 
-/***
- *** General Macros.
- ***/
-
-/*%
- * Use this to hide unused function arguments.
- * \code
- * int
- * foo(char *bar)
- * {
- *	UNUSED(bar);
- * }
- * \endcode
- */
-#define UNUSED(x)      (void)(x)
-
 /*%
  * We use macros instead of calling the routines directly because
  * the capital letters make the locking stand out.
- * We RUNTIME_CHECK for success since in general there's no way
- * for us to continue if they fail.
  */
 
-#ifdef ISC_UTIL_TRACEON
-#define ISC_UTIL_TRACE(a) a
-#include <stdio.h>		/* Required for fprintf/stderr when tracing. */
-#else
-#define ISC_UTIL_TRACE(a)
-#endif
-
 #include "isc/result.h"		/* Contractual promise. */
 
 /*
@@ -64,15 +39,8 @@
 
 /*% Unexpected Error */
 #define UNEXPECTED_ERROR		isc_error_unexpected
-/*% Runtime Check */
-#define RUNTIME_CHECK(cond)		ISC_ERROR_RUNTIMECHECK(cond)
 
 /* hack to ignore GCC Unused Result */
 #define ISC_IGNORE(r) do{if(r){}}while(0)
 
-/*%
- * Time
- */
-#define TIME_NOW(tp) 	RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS)
-
 #endif /* GUARD_ISC_UTIL_H */


=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -112,14 +112,6 @@ static int	ntpdmain(int, char **) __attribute__((noreturn));
 static void	mainloop		(void)
 			__attribute__	((__noreturn__));
 static void	set_process_priority	(void);
-static void	library_fatal_error	(const char *, int,
-					 const char *, va_list)
-					ISC_FORMAT_PRINTF(3, 0)
-			__attribute__	((__noreturn__));
-static void	library_unexpected_error(const char *, int,
-					 const char *, va_list)
-					ISC_FORMAT_PRINTF(3, 0);
-
 static  void    close_all_beyond(int);
 static  void    close_all_except(int);
 
@@ -565,13 +557,6 @@ ntpdmain(
 		msyslog(LOG_INFO, "%s", buf);
 	}
 
-	/*
-	 * Install trap handlers to log errors and assertion failures.
-	 * Default handlers print to stderr which doesn't work if detached.
-	 */
-	isc_error_setfatal(library_fatal_error);
-	isc_error_setunexpected(library_unexpected_error);
-
 	uid = getuid();
 	if (uid && !dumpopts) {
 		termlogit = true;
@@ -1215,59 +1200,6 @@ static void check_minsane()
 
 }
 
-
-
-/*
- * library_fatal_error - Handle fatal errors from our libraries.
- */
-static void
-library_fatal_error(
-	const char *file,
-	int line,
-	const char *format,
-	va_list args
-	)
-{
-	char errbuf[256];
-
-	isc_error_setfatal(NULL);  /* Avoid recursion */
-
-	msyslog(LOG_ERR, "%s:%d: fatal error:", file, line);
-	vsnprintf(errbuf, sizeof(errbuf), format, args);
-	msyslog(LOG_ERR, "%s", errbuf);
-	msyslog(LOG_ERR, "exiting (due to fatal error in library)");
-
-	abort();
-}
-
-
-/*
- * library_unexpected_error - Handle non fatal errors from our libraries.
- */
-# define MAX_UNEXPECTED_ERRORS 100
-static int unexpected_error_cnt = 0;
-static void
-library_unexpected_error(
-	const char *file,
-	int line,
-	const char *format,
-	va_list args
-	)
-{
-	char errbuf[256];
-
-	if (unexpected_error_cnt >= MAX_UNEXPECTED_ERRORS)
-		return;	/* avoid clutter in log */
-
-	msyslog(LOG_ERR, "%s:%d: unexpected error:", file, line);
-	vsnprintf(errbuf, sizeof(errbuf), format, args);
-	msyslog(LOG_ERR, "%s", errbuf);
-
-	if (++unexpected_error_cnt == MAX_UNEXPECTED_ERRORS)
-		msyslog(LOG_ERR, "Too many errors.  Shutting up.");
-
-}
-
 # ifdef DEBUG
 
 /*



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/657d6d7daa3aa673d2dcf8b5bdcd63e7f487164c...759eaded7240cb3094ca818063d449c8f2e2deeb

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/657d6d7daa3aa673d2dcf8b5bdcd63e7f487164c...759eaded7240cb3094ca818063d449c8f2e2deeb
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/20170606/c92f1b18/attachment.html>


More information about the vc mailing list