[Git][NTPsec/ntpsec][master] 7 commits: libisc: merge isc/magic.h into interfaceiter.c

Gary E. Miller gitlab at mg.gitlab.com
Tue Jun 6 22:03:23 UTC 2017


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


Commits:
d1ff70dd by Gary E. Miller at 2017-06-06T13:39:17-07:00
libisc: merge isc/magic.h into interfaceiter.c

It is only used in interfaceiter.c

- - - - -
bb819836 by Gary E. Miller at 2017-06-06T13:46:47-07:00
libisc: remove unused isc_error_setfatal() prototype.

Plus some comment clean up.

- - - - -
66b56e1a by Gary E. Miller at 2017-06-06T13:49:33-07:00
libisc: remove more unused stuff in isc/error.h

- - - - -
72cf6801 by Gary E. Miller at 2017-06-06T14:19:00-07:00
libisc: improve the UNEXPECTED_ERROR() macro.

Make it look like the REQUIRE() macro and handle __FILE__ and
__LINE__ automagically.

- - - - -
98b61107 by Gary E. Miller at 2017-06-06T14:30:31-07:00
libisc: remove function shim in library_unexpected_error() path.

isc_error_unexpected() always just called library_unexpected_error()

- - - - -
a07928fe by Gary E. Miller at 2017-06-06T14:40:29-07:00
libisc: replace ISC_IGNORE() macro with (void).

This code has to be ancient, before (void).

- - - - -
f12a56a0 by Gary E. Miller at 2017-06-06T14:43:55-07:00
libisc: remove unused header, and unused prototype from isc/error.h

- - - - -


8 changed files:

- libisc/error.c
- libisc/ifiter_getifaddrs.c
- libisc/ifiter_ioctl.c
- libisc/ifiter_sysctl.c
- libisc/include/isc/error.h
- − libisc/include/isc/magic.h
- libisc/interfaceiter.c
- libisc/net.c


Changes:

=====================================
libisc/error.c
=====================================
--- a/libisc/error.c
+++ b/libisc/error.c
@@ -17,35 +17,16 @@
 
 #include "isc/error.h"
 
-/*% Default unexpected callback. */
-static void	library_unexpected_error(const char *, int,
-					 const char *, va_list)
-					ISC_FORMAT_PRINTF(3, 0);
 
+#define MAX_UNEXPECTED_ERRORS 100
 void
 isc_error_unexpected(const char *file, int line, const char *format, ...) {
 	va_list args;
-
-	va_start(args, format);
-	library_unexpected_error(file, line, format, args);
-	va_end(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);
+
 	if (unexpected_error_cnt >= MAX_UNEXPECTED_ERRORS)
 		return;	/* avoid clutter in log */
 
@@ -55,5 +36,4 @@ library_unexpected_error(
 
 	if (++unexpected_error_cnt == MAX_UNEXPECTED_ERRORS)
 		msyslog(LOG_ERR, "Too many errors.  Shutting up.");
-
 }


=====================================
libisc/ifiter_getifaddrs.c
=====================================
--- a/libisc/ifiter_getifaddrs.c
+++ b/libisc/ifiter_getifaddrs.c
@@ -68,7 +68,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 	if (!seenv6) {
 		iter->proc = fopen("/proc/net/if_inet6", "r");
 		if (iter->proc == NULL) {
-			ISC_IGNORE(strerror_r(errno, strbuf, sizeof(strbuf)));
+			(void)strerror_r(errno, strbuf, sizeof(strbuf));
 /*			isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
 				      ISC_LOGMODULE_SOCKET, ISC_LOG_WARNING,
 				      "failed to open /proc/net/if_inet6");
@@ -87,9 +87,8 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 			break;
 	}
 	if (ret < 0) {
-	    ISC_IGNORE(strerror_r(errno, strbuf, sizeof(strbuf)));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-                		 "getting interface addresses: getifaddrs: %s",
+		(void)strerror_r(errno, strbuf, sizeof(strbuf));
+		UNEXPECTED_ERROR("getting interface addresses: getifaddrs: %s",
 				 strbuf);
 		result = ISC_R_UNEXPECTED;
 		goto failure;


=====================================
libisc/ifiter_ioctl.c
=====================================
--- a/libisc/ifiter_ioctl.c
+++ b/libisc/ifiter_ioctl.c
@@ -127,9 +127,8 @@ getbuf4(isc_interfaceiter_t *iter) {
 		    == -1) {
 			if (errno != EINVAL) {
 				strerror_r(errno, strbuf, sizeof(strbuf));
-				UNEXPECTED_ERROR(__FILE__, __LINE__,
-							"get interface "
-							"configuration: %s",
+				UNEXPECTED_ERROR("get interface "
+						 "configuration: %s",
 						 strbuf);
 				goto unexpected;
 			}
@@ -151,8 +150,7 @@ getbuf4(isc_interfaceiter_t *iter) {
 				break;
 		}
 		if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "get interface configuration: "
+			UNEXPECTED_ERROR("get interface configuration: "
 					 "maximum buffer size exceeded");
 			goto unexpected;
 		}
@@ -216,9 +214,8 @@ getbuf6(isc_interfaceiter_t *iter) {
 #endif
 			if (errno != EINVAL) {
 				strerror_r(errno, strbuf, sizeof(strbuf));
-				UNEXPECTED_ERROR(__FILE__, __LINE__,
-							"get interface "
-							"configuration: %s",
+				UNEXPECTED_ERROR("get interface "
+						 "configuration: %s",
 						 strbuf);
 				result = ISC_R_UNEXPECTED;
 				goto cleanup;
@@ -241,8 +238,7 @@ getbuf6(isc_interfaceiter_t *iter) {
 				break;
 		}
 		if (iter->bufsize6 >= IFCONF_BUFSIZE_MAX) {
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "get interface configuration: "
+			UNEXPECTED_ERROR("get interface configuration: "
 					 "maximum buffer size exceeded");
 			result = ISC_R_UNEXPECTED;
 			goto cleanup;
@@ -304,8 +300,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 		 */
 		if ((iter->socket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
 			strerror_r(errno, strbuf, sizeof(strbuf));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "making interface scan socket: %s",
+			UNEXPECTED_ERROR("making interface scan socket: %s",
 					 strbuf);
 			result = ISC_R_UNEXPECTED;
 			goto socket6_failure;
@@ -317,8 +312,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 #endif
 	if ((iter->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "making interface scan socket: %s",
+		UNEXPECTED_ERROR("making interface scan socket: %s",
 				 strbuf);
 		result = ISC_R_UNEXPECTED;
 		goto socket_failure;
@@ -441,8 +435,7 @@ internal_current4(isc_interfaceiter_t *iter) {
 	 */
 	if (isc_ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "%s: getting interface flags: %s",
+		UNEXPECTED_ERROR("%s: getting interface flags: %s",
 				 ifreq.ifr_name, strbuf);
 		return (ISC_R_IGNORE);
 	}
@@ -476,8 +469,7 @@ internal_current4(isc_interfaceiter_t *iter) {
 
 	if (isc_ioctl(iter->socket, SIOCGLIFADDR, &lifreq) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "%s: getting interface address: %s",
+		UNEXPECTED_ERROR("%s: getting interface address: %s",
 				 ifreq.ifr_name, strbuf);
 		return (ISC_R_IGNORE);
 	}
@@ -516,8 +508,7 @@ internal_current4(isc_interfaceiter_t *iter) {
 		if (isc_ioctl(iter->socket, SIOCGIFDSTADDR, (char *)&ifreq)
 		    < 0) {
 			strerror_r(errno, strbuf, sizeof(strbuf));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "%s: getting destination address: %s",
+			UNEXPECTED_ERROR("%s: getting destination address: %s",
 					 ifreq.ifr_name, strbuf);
 			return (ISC_R_IGNORE);
 		}
@@ -535,8 +526,7 @@ internal_current4(isc_interfaceiter_t *iter) {
 		if (isc_ioctl(iter->socket, SIOCGIFBRDADDR, (char *)&ifreq)
 		    < 0) {
 			strerror_r(errno, strbuf, sizeof(strbuf));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "%s: getting broadcast address: %s",
+			UNEXPECTED_ERROR("%s: getting broadcast address: %s",
 					 ifreq.ifr_name, strbuf);
 			return (ISC_R_IGNORE);
 		}
@@ -556,8 +546,7 @@ internal_current4(isc_interfaceiter_t *iter) {
 	 */
 	if (isc_ioctl(iter->socket, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "%s: getting netmask: %s",
+		UNEXPECTED_ERROR("%s: getting netmask: %s",
 				 ifreq.ifr_name, strbuf);
 		return (ISC_R_IGNORE);
 	}
@@ -637,8 +626,7 @@ internal_current6(isc_interfaceiter_t *iter) {
 	 */
 	if (isc_ioctl(fd, SIOCGLIFFLAGS, (char *) &lifreq) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "%s: getting interface flags: %s",
+		UNEXPECTED_ERROR("%s: getting interface flags: %s",
 				 lifreq.lifr_name, strbuf);
 		return (ISC_R_IGNORE);
 	}
@@ -677,8 +665,7 @@ internal_current6(isc_interfaceiter_t *iter) {
 		if (isc_ioctl(fd, SIOCGLIFDSTADDR, (char *)&lifreq)
 		    < 0) {
 			strerror_r(errno, strbuf, sizeof(strbuf));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "%s: getting destination address: %s",
+			UNEXPECTED_ERROR("%s: getting destination address: %s",
 					 lifreq.lifr_name, strbuf);
 			return (ISC_R_IGNORE);
 		}
@@ -698,8 +685,7 @@ internal_current6(isc_interfaceiter_t *iter) {
 		if (isc_ioctl(iter->socket, SIOCGLIFBRDADDR, (char *)&lifreq)
 		    < 0) {
 			strerror_r(errno, strbuf, sizeof(strbuf));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "%s: getting broadcast address: %s",
+			UNEXPECTED_ERROR("%s: getting broadcast address: %s",
 					 lifreq.lifr_name, strbuf);
 			return (ISC_R_IGNORE);
 		}
@@ -743,8 +729,7 @@ internal_current6(isc_interfaceiter_t *iter) {
 	 */
 	if (isc_ioctl(fd, SIOCGLIFNETMASK, (char *)&lifreq) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "%s: getting netmask: %s",
+		UNEXPECTED_ERROR("%s: getting netmask: %s",
 				 lifreq.lifr_name, strbuf);
 		return (ISC_R_IGNORE);
 	}


=====================================
libisc/ifiter_sysctl.c
=====================================
--- a/libisc/ifiter_sysctl.c
+++ b/libisc/ifiter_sysctl.c
@@ -70,8 +70,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 	bufsize = 0;
 	if (sysctl(mib, 6, NULL, &bufsize, NULL, (size_t) 0) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "getting interface list size: sysctl: %s",
+		UNEXPECTED_ERROR("getting interface list size: sysctl: %s",
 				 strbuf);
 		result = ISC_R_UNEXPECTED;
 		goto failure;
@@ -87,8 +86,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
 	bufused = bufsize;
 	if (sysctl(mib, 6, iter->buf, &bufused, NULL, (size_t) 0) < 0) {
 		strerror_r(errno, strbuf, sizeof(strbuf));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "getting interface list: sysctl: %s",
+		UNEXPECTED_ERROR("getting interface list: sysctl: %s",
 				 strbuf);
 		result = ISC_R_UNEXPECTED;
 		goto failure;


=====================================
libisc/include/isc/error.h
=====================================
--- a/libisc/include/isc/error.h
+++ b/libisc/include/isc/error.h
@@ -10,8 +10,6 @@
 
 /*! \file isc/error.h */
 
-#include <stdarg.h>
-
 /*
  * ISC_FORMAT_PRINTF().
  *
@@ -28,30 +26,13 @@
 #endif
 
 
-typedef void (*isc_errorcallback_t)(const char *, int, const char *, va_list);
-
-/*% set unexpected error */
-void
-isc_error_setunexpected(isc_errorcallback_t);
-
-/*% set fatal error */
-void
-isc_error_setfatal(isc_errorcallback_t);
-
-/*% unexpected error */
+/* unexpected error */
 void
 isc_error_unexpected(const char *, int, const char *, ...)
      ISC_FORMAT_PRINTF(3, 4);
 
-/*% Unexpected Error */
-#define UNEXPECTED_ERROR		isc_error_unexpected
-
-/* hack to ignore GCC Unused Result */
-#define ISC_IGNORE(r) do{if(r){}}while(0)
-
-/*% fatal error */
-void
-isc_error_fatal(const char *, int, const char *, ...)
-ISC_FORMAT_PRINTF(3, 4) __attribute__	((__noreturn__));
+/* Unexpected Error */
+#define UNEXPECTED_ERROR(fmt, ...) \
+	isc_error_unexpected(__FILE__, __LINE__, fmt, __VA_ARGS__)
 
 #endif /* GUARD_ISC_ERROR_H */


=====================================
libisc/include/isc/magic.h deleted
=====================================
--- a/libisc/include/isc/magic.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2001  Internet Software Consortium.
- * Copyright 2015 by the NTPsec project contributors
- * SPDX-License-Identifier: ISC
- */
-
-#ifndef GUARD_ISC_MAGIC_H
-#define GUARD_ISC_MAGIC_H 1
-
-/*! \file isc/magic.h */
-
-typedef struct {
-	unsigned int magic;
-} isc__magic_t;
-
-
-/*%
- * To use this macro the magic number MUST be the first thing in the
- * structure, and MUST be of type "unsigned int".
- * The intent of this is to allow magic numbers to be checked even though
- * the object is otherwise opaque.
- */
-#define ISC_MAGIC_VALID(a,b)	(((a) != NULL) && \
-				 (((const isc__magic_t *)(a))->magic == (b)))
-
-#define ISC_MAGIC(a, b, c, d)	((a) << 24 | (b) << 16 | (c) << 8 | (d))
-
-#endif /* GUARD_ISC_MAGIC_H */


=====================================
libisc/interfaceiter.c
=====================================
--- a/libisc/interfaceiter.c
+++ b/libisc/interfaceiter.c
@@ -22,7 +22,6 @@
 
 #include "ntp_assert.h"
 #include "isc/interfaceiter.h"
-#include "isc/magic.h"
 #include "isc/mem.h"
 #include "isc/netaddr.h"
 #include "isc/result.h"
@@ -37,6 +36,22 @@
 # include <linux/if_addr.h>
 #endif
 
+
+typedef struct {
+	unsigned int magic;
+} isc__magic_t;
+
+/*
+ * To use this macro the magic number MUST be the first thing in the
+ * structure, and MUST be of type "unsigned int".
+ * The intent of this is to allow magic numbers to be checked even though
+ * the object is otherwise opaque.
+ */
+#define ISC_MAGIC_VALID(a,b)	(((a) != NULL) && \
+				 (((const isc__magic_t *)(a))->magic == (b)))
+
+#define ISC_MAGIC(a, b, c, d)	((a) << 24 | (b) << 16 | (c) << 8 | (d))
+
 /* Common utility functions */
 
 /*%


=====================================
libisc/net.c
=====================================
--- a/libisc/net.c
+++ b/libisc/net.c
@@ -50,9 +50,8 @@ try_proto(int domain) {
 #endif
 			return (ISC_R_NOTFOUND);
 		default:
-			ISC_IGNORE(strerror_r(errno, strbuf, sizeof(strbuf)));
-			UNEXPECTED_ERROR(__FILE__, __LINE__,
-					 "socket() failed: %s", strbuf);
+			(void)strerror_r(errno, strbuf, sizeof(strbuf));
+			UNEXPECTED_ERROR("socket() failed: %s", strbuf);
 			return (ISC_R_UNEXPECTED);
 		}
 	}
@@ -157,9 +156,8 @@ try_ipv6only(void) {
 	/* check for TCP sockets */
 	s = socket(PF_INET6, SOCK_STREAM, 0);
 	if (s == -1) {
-		ISC_IGNORE(strerror_r(errno, strbuf, sizeof(strbuf)));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "socket() failed: %s", strbuf);
+		(void)strerror_r(errno, strbuf, sizeof(strbuf));
+		UNEXPECTED_ERROR("socket() failed: %s", strbuf);
 		ipv6only_result = ISC_R_UNEXPECTED;
 		return;
 	}
@@ -175,9 +173,8 @@ try_ipv6only(void) {
 	/* check for UDP sockets */
 	s = socket(PF_INET6, SOCK_DGRAM, 0);
 	if (s == -1) {
-		ISC_IGNORE(strerror_r(errno, strbuf, sizeof(strbuf)));
-		UNEXPECTED_ERROR(__FILE__, __LINE__,
-				 "socket() failed: %s", strbuf);
+		(void)strerror_r(errno, strbuf, sizeof(strbuf));
+		UNEXPECTED_ERROR("socket() failed: %s", strbuf);
 		ipv6only_result = ISC_R_UNEXPECTED;
 		return;
 	}



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c845da3db793b596664106b74417f89ef5e74e4b...f12a56a09c1327d600794f8c96ca8230da16d550

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c845da3db793b596664106b74417f89ef5e74e4b...f12a56a09c1327d600794f8c96ca8230da16d550
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/8d2a3486/attachment.html>


More information about the vc mailing list