You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ba...@apache.org on 2020/08/27 23:15:51 UTC

[kudu] branch master updated: [net] KUDU-3184: Fix GetFQDN() when canonical name returns null

This is an automated email from the ASF dual-hosted git repository.

bankim pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 4eff1e7  [net] KUDU-3184: Fix GetFQDN() when canonical name returns null
4eff1e7 is described below

commit 4eff1e7434a2c63f645b9996fa6de03b3701b80a
Author: Mahesh Reddy <mr...@cloudera.com>
AuthorDate: Tue Aug 25 15:51:42 2020 -0700

    [net] KUDU-3184: Fix GetFQDN() when canonical name returns null
    
    Issue occured if FQDN didn't have domain name (ex .local).
    Canonical name wasn't assigned FQDN and returned null.
    Ran into this issue with macOS version 10.15.6.
    
    Change-Id: I6bfc1a39175761e3a2f19280066cb1c8343fe79d
    Reviewed-on: http://gerrit.cloudera.org:8080/16364
    Reviewed-by: Bankim Bhavsar <ba...@cloudera.com>
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <as...@cloudera.com>
---
 src/kudu/util/net/net_util.cc | 11 +++++++----
 src/kudu/util/net/net_util.h  |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/kudu/util/net/net_util.cc b/src/kudu/util/net/net_util.cc
index f74b324..87df153 100644
--- a/src/kudu/util/net/net_util.cc
+++ b/src/kudu/util/net/net_util.cc
@@ -15,12 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
+#include "kudu/util/net/net_util.h"
+
 #include <arpa/inet.h>
-#include <sys/socket.h>
 #include <ifaddrs.h>
 #include <limits.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <sys/socket.h>
 #include <unistd.h>
 
 #include <cerrno>
@@ -49,7 +51,6 @@
 #include "kudu/util/debug/trace_event.h"
 #include "kudu/util/errno.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/net/net_util.h"
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/net/socket.h"
 #include "kudu/util/scoped_cleanup.h"
@@ -413,8 +414,10 @@ Status GetFQDN(string* hostname) {
     TRACE_EVENT0("net", "getaddrinfo");
     RETURN_NOT_OK(GetAddrInfo(*hostname, hints, op_description, &result));
   }
-
-  *hostname = result->ai_canonname;
+  // On macOS ai_cannonname returns null when FQDN doesn't have domain name (ex .local)
+  if (result->ai_canonname != nullptr) {
+    *hostname = result->ai_canonname;
+  }
   return Status::OK();
 }
 
diff --git a/src/kudu/util/net/net_util.h b/src/kudu/util/net/net_util.h
index 01546b6..d27503a 100644
--- a/src/kudu/util/net/net_util.h
+++ b/src/kudu/util/net/net_util.h
@@ -175,6 +175,7 @@ Status GetHostname(std::string* hostname);
 Status GetLocalNetworks(std::vector<Network>* net);
 
 // Return the local machine's FQDN.
+// If domain name is not available, FQDN returns hostname.
 Status GetFQDN(std::string* hostname);
 
 // Returns a single socket address from a HostPort.