DNS resolution should fail if no DNS servers are available. This
patch fixes it and also enables users to use environment variable
OVS_RESOLV_CONF to specify the path for DNS server configuration
file.

Suggested-by: Ben Pfaff <[email protected]>
Suggested-by: Mark Michelson <[email protected]>
Signed-off-by: Yifeng Sun <[email protected]>
---
 lib/dns-resolve.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/dns-resolve.c b/lib/dns-resolve.c
index 3c6d70e8fbba..60757cb1eb8a 100644
--- a/lib/dns-resolve.c
+++ b/lib/dns-resolve.c
@@ -83,14 +83,26 @@ dns_resolve_init(bool is_daemon)
     }
 
 #ifdef __linux__
-    const char *filename = "/etc/resolv.conf";
+    const char *filename = getenv("OVS_RESOLV_CONF");
+    if (filename == NULL) {
+        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));
+            ub_ctx_delete(ub_ctx__);
+            ub_ctx__ = NULL;
+            return;
         }
+    } else {
+        VLOG_WARN_RL(&rl, "Failed to read %s: %s",
+                     filename, ovs_strerror(errno));
+        ub_ctx_delete(ub_ctx__);
+        ub_ctx__ = NULL;
+        return;
     }
 #endif
 
-- 
2.7.4

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

Reply via email to