116 lines
3.1 KiB
Diff
116 lines
3.1 KiB
Diff
commit 0148ecaea08691537f51c0aea9c3387cd1d34745
|
|
Author: Miroslav Lichvar <mlichvar@redhat.com>
|
|
Date: Mon Nov 10 14:42:41 2008 +0100
|
|
|
|
Retry name resolving after temporary failure few times before giving up
|
|
|
|
This is a temporary fix to allow starting when resolv.conf is not ready yet
|
|
(e.g. when using NetworkManager). It may delay start up to 1022 seconds.
|
|
|
|
diff --git a/cmdparse.c b/cmdparse.c
|
|
index 7acc44c..e09db45 100644
|
|
--- a/cmdparse.c
|
|
+++ b/cmdparse.c
|
|
@@ -61,7 +61,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|
|
|
ok = 0;
|
|
if (sscanf(line, "%" SMAXLEN "s%n", hostname, &n) == 1) {
|
|
- src->ip_addr = DNS_Name2IPAddress(hostname);
|
|
+ src->ip_addr = DNS_Name2IPAddressRetry(hostname);
|
|
if (src->ip_addr != DNS_Failed_Address) {
|
|
ok = 1;
|
|
}
|
|
diff --git a/conf.c b/conf.c
|
|
index e34927e..8e6c1d9 100644
|
|
--- a/conf.c
|
|
+++ b/conf.c
|
|
@@ -584,7 +584,7 @@ parse_initstepslew(const char *line)
|
|
}
|
|
while (*p) {
|
|
if (sscanf(p, "%" SHOSTNAME_LEN "s%n", hostname, &n) == 1) {
|
|
- ip_addr = DNS_Name2IPAddress(hostname);
|
|
+ ip_addr = DNS_Name2IPAddressRetry(hostname);
|
|
if (ip_addr != DNS_Failed_Address) {
|
|
init_srcs_ip[n_init_srcs] = ip_addr;
|
|
++n_init_srcs;
|
|
@@ -746,7 +746,7 @@ parse_allow_deny(const char *line, AllowDeny *list, int allow)
|
|
}
|
|
|
|
} else {
|
|
- ip_addr = DNS_Name2IPAddress(p);
|
|
+ ip_addr = DNS_Name2IPAddressRetry(p);
|
|
if (ip_addr != DNS_Failed_Address) {
|
|
new_node = MallocNew(AllowDeny);
|
|
new_node->allow = allow;
|
|
diff --git a/nameserv.c b/nameserv.c
|
|
index dd610df..9a25254 100644
|
|
--- a/nameserv.c
|
|
+++ b/nameserv.c
|
|
@@ -32,18 +32,28 @@
|
|
#include "sysincl.h"
|
|
|
|
#include "nameserv.h"
|
|
+#include <resolv.h>
|
|
|
|
/* ================================================== */
|
|
|
|
-unsigned long
|
|
-DNS_Name2IPAddress(const char *name)
|
|
+static unsigned int retries = 0;
|
|
+
|
|
+static unsigned long
|
|
+Name2IPAddress(const char *name, int retry)
|
|
{
|
|
struct hostent *host;
|
|
unsigned char *address0;
|
|
unsigned long result;
|
|
|
|
+try_again:
|
|
host = gethostbyname(name);
|
|
if (host == NULL) {
|
|
+ if (retry && h_errno == TRY_AGAIN && retries < 10) {
|
|
+ sleep(2 << retries);
|
|
+ retries++;
|
|
+ res_init();
|
|
+ goto try_again;
|
|
+ }
|
|
result = DNS_Failed_Address;
|
|
} else {
|
|
address0 = host->h_addr_list[0];
|
|
@@ -54,7 +64,22 @@ DNS_Name2IPAddress(const char *name)
|
|
}
|
|
|
|
return result;
|
|
+}
|
|
+
|
|
+/* ================================================== */
|
|
+
|
|
+unsigned long
|
|
+DNS_Name2IPAddress(const char *name)
|
|
+{
|
|
+ return Name2IPAddress(name, 0);
|
|
+}
|
|
|
|
+/* ================================================== */
|
|
+
|
|
+unsigned long
|
|
+DNS_Name2IPAddressRetry(const char *name)
|
|
+{
|
|
+ return Name2IPAddress(name, 1);
|
|
}
|
|
|
|
/* ================================================== */
|
|
diff --git a/nameserv.h b/nameserv.h
|
|
index e62f334..69ceef8 100644
|
|
--- a/nameserv.h
|
|
+++ b/nameserv.h
|
|
@@ -36,6 +36,8 @@ static const unsigned long DNS_Failed_Address = 0x0UL;
|
|
|
|
extern unsigned long DNS_Name2IPAddress(const char *name);
|
|
|
|
+extern unsigned long DNS_Name2IPAddressRetry(const char *name);
|
|
+
|
|
const char *DNS_IPAddress2Name(unsigned long ip_addr);
|
|
|
|
#endif /* GOT_NAMESERV_H */
|