[PATCH 2/2] Log a message when we can't resolve a hostname

From: John Haxby <john.haxby_at_oracle.com>
Date: Fri, 23 Jul 2010 10:42:15 +0100

Logging a message to another host should not be silent. Add a log
message each time the call to getaddrinfo() fails so that something
is recorded.

Signed-off-by: John Haxby <john.haxby_at_oracle.com>

---
 syslogd.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/syslogd.c b/syslogd.c
index 2829342..95e98e6 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -1885,9 +1885,16 @@ void fprintlog(f, from, flags, msg)
 			hints.ai_family = family;
 			hints.ai_socktype = SOCK_DGRAM;
 			if ((err = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints, &ai))) {
-				dprintf("Failure: %s\n", gai_strerror(err));
+				char line[MAXLINE+1];
+				snprintf(line, sizeof(line), "%s: %s",
+					 f->f_un.f_forw.f_hname, gai_strerror(err));
+				logerror(line);
+				dprintf("Failure: %s\n", line);
 				dprintf("Retries: %d\n", f->f_retrycount);
 				if ( --f->f_retrycount <= 0 ) {
+					snprintf(line, sizeof(line), "%s: giving up",
+						 f->f_un.f_forw.f_hname);
+					logerror(line);
 					dprintf("Giving up.\n");
 					f->f_type = F_UNUSED;
 					exit(0);
@@ -2678,6 +2685,7 @@ void cfline(line, f)
 	int syncfile;
 #ifdef SYSLOG_INET
 	struct addrinfo hints, *ai;
+	int err;
 #endif
 	char buf[MAXLINE];
 	char xbuf[200];
@@ -2838,13 +2846,16 @@ void cfline(line, f)
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_family = family;
 		hints.ai_socktype = SOCK_DGRAM;
-		if (getaddrinfo(p, "syslog", &hints, &ai)) {
+		if ((err = getaddrinfo(p, "syslog", &hints, &ai))) {
 			/*
 			 * The host might be unknown due to an
 			 * inaccessible nameserver (perhaps on the
 			 * same host). We try to get the ip number
 			 * later, like FORW_SUSP.
 			 */
+			char errline[MAXLINE+1];
+			snprintf(errline, sizeof(errline), "%s: %s", p, gai_strerror(err));
+			logerror(errline);
 			f->f_type = F_FORW_UNKN;
 			f->f_retrycount = INET_RETRY_MAX;
 			f->f_time = time ( (time_t *)0 );
-- 
1.7.1.1
Received on Fri Jul 23 2010 - 11:42:15 CEST

This archive was generated by hypermail 2.2.0 : Fri Jul 23 2010 - 11:42:46 CEST