diff mbox series

[ovs-dev] dns-resolve: Only ask unbound to read /etc/resolv.conf if it exists.

Message ID 20180807194013.28472-1-blp@ovn.org
State Accepted
Headers show
Series [ovs-dev] dns-resolve: Only ask unbound to read /etc/resolv.conf if it exists. | expand

Commit Message

Ben Pfaff Aug. 7, 2018, 7:40 p.m. UTC
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 <fbl@sysclose.org>
Reporetd-at: https://mail.openvswitch.org/pipermail/ovs-dev/2018-August/350751.html
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/dns-resolve.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Flavio Leitner Aug. 7, 2018, 8:41 p.m. UTC | #1
On Tue, Aug 07, 2018 at 12:40:13PM -0700, Ben Pfaff wrote:
> 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 <fbl@sysclose.org>
> Reporetd-at: https://mail.openvswitch.org/pipermail/ovs-dev/2018-August/350751.html
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---

Thanks Ben, looks good and works here.
Acked-by: Flavio Leitner <fbl@sysclose.org>
Ben Pfaff Aug. 7, 2018, 9:45 p.m. UTC | #2
On Tue, Aug 07, 2018 at 05:41:24PM -0300, Flavio Leitner wrote:
> On Tue, Aug 07, 2018 at 12:40:13PM -0700, Ben Pfaff wrote:
> > 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 <fbl@sysclose.org>
> > Reporetd-at: https://mail.openvswitch.org/pipermail/ovs-dev/2018-August/350751.html
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> 
> Thanks Ben, looks good and works here.
> Acked-by: Flavio Leitner <fbl@sysclose.org>

Thanks, applied to master and branch-2.10.
diff mbox series

Patch

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));