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 <[email protected]>
Reporetd-at: 
https://mail.openvswitch.org/pipermail/ovs-dev/2018-August/350751.html
Signed-off-by: Ben Pfaff <[email protected]>
---
 lib/dns-resolve.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/dns-resolve.c b/lib/dns-resolve.c
index f1f91129609a..299ab27ab5ca 100644
--- a/lib/dns-resolve.c
+++ b/lib/dns-resolve.c
@@ -22,6 +22,7 @@
 #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");
-    if (retval != 0) {
-        VLOG_WARN_RL(&rl, "Failed to read /etc/resolv.conf: %s",
-                     ub_strerror(retval));
+    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 %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));
-- 
2.16.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to