dns-resolve: Only ask unbound to read /etc/resolv.conf if it exists.
The unbound library complains if we ask it to read /etc/resolv.conf but
that file doesn't exist.  It's better to just skip reading it in that case.
Reported-by: Flavio Leitner
Reporetd-at:
Acked-by: Flavio Leitner
#include <arpa/nameser.h>
#include <errno.h>
#include <string.h>
+#include <sys/stat.h>
#include <unbound.h>
#include "hash.h"
#include "openvswitch/hmap.h"
@@ -81,17 +82,20 @@ dns_resolve_init(bool is_daemon)
return;
}
- int retval;
#ifdef __linux__
- retval = ub_ctx_resolvconf(ub_ctx__, "/etc/resolv.conf");
+ const char *filename = "/etc/resolv.conf";
+ struct stat s;
+ if (!stat(filename, &s) || errno != ENOENT) {
+ int retval = ub_ctx_resolvconf(ub_ctx__, filename);
if (retval != 0) {
- VLOG_WARN_RL(&rl, "Failed to read /etc/resolv.conf: %s",
- ub_strerror(retval));
+ VLOG_WARN_RL(&rl, "Failed to read %s: %s",
+ filename, ub_strerror(retval));
+ }
}
#endif
/* Handles '/etc/hosts' on Linux and 'WINDIR/etc/hosts' on Windows. */
- retval = ub_ctx_hosts(ub_ctx__, NULL);
+ int retval = ub_ctx_hosts(ub_ctx__, NULL);
if (retval != 0) {
VLOG_WARN_RL(&rl, "Failed to read etc/hosts: %s",
ub_strerror(retval));
