From b7d4225ef18f2057fb64d25b2f3c7f7e7d910d53 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 28 Nov 2019 14:41:03 +0100 Subject: [PATCH] syslogd: Retry address lookup forever, never give up When logging to a remote server, using @fqdn syntax in syslog.conf, syslogd calls getaddrinfo() to resolve the IP address. Older versions of syslogd gave up after 10 retries. We want to retry forever since we may be running in a setup with bad network connection to the DNS server for longer periods of time. This patch only removes the 'give up' mechanism, which unfortunately reused the f_prevcount value, which in turn could cause that value to become -1 and thus trigger an assert(). With this code out of the way, and the type change in the previous commit, the counter can never again be negative. Note: The configurable suspend time before trying again remains at its default of 3 minutes. Signed-off-by: Joachim Nilsson --- src/syslogd.c | 16 ++-------------- src/syslogd.h | 1 - 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index 35fda4b..b083eaf 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -1427,17 +1427,7 @@ void fprintlog_write(struct filed *f, struct iovec *iov, int iovcnt, int flags) logit("Forwarding suspension to %s:%s over, retrying\n", host, serv); err = nslookup(host, serv, &ai); if (err) { - logit("Failure resolving %s:%s: %s\n", host, serv, gai_strerror(err)); - logit("Retries: %d\n", f->f_prevcount); - if (--f->f_prevcount < 0) { - WARN("Still cannot find %s, giving up: %s", - host, gai_strerror(err)); - f->f_type = F_UNUSED; - } else { - WARN("Still cannot find %s, will try again later: %s", - host, gai_strerror(err)); - logit("Left retries: %d\n", f->f_prevcount); - } + WARN("Failure resolving %s:%s: %s", host, serv, gai_strerror(err)); } else { NOTE("Found %s, resuming operation.", host); f->f_un.f_forw.f_addr = ai; @@ -2464,16 +2454,14 @@ static struct filed *cfline(char *line) err = nslookup(p, bp, &ai); if (err) { - WARN("Cannot find %s, will try again later: %s", p, gai_strerror(err)); /* * 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. */ f->f_type = F_FORW_UNKN; - f->f_prevcount = INET_RETRY_MAX; f->f_time = time(NULL); - f->f_un.f_forw.f_addr = NULL; + WARN("Cannot find %s, will try again later: %s", p, gai_strerror(err)); } else { f->f_type = F_FORW; f->f_un.f_forw.f_addr = ai; diff --git a/src/syslogd.h b/src/syslogd.h index 5b016b9..b9d872e 100644 --- a/src/syslogd.h +++ b/src/syslogd.h @@ -106,7 +106,6 @@ #ifndef INET_SUSPEND_TIME #define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ #endif -#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ #define LIST_DELIMITER ':' /* delimiter between two hosts */