Ack.

Thanks,
Ramesh.

On 3/30/2017 5:51 PM, Anders Widell wrote:
>   src/base/conf.cc |  28 +++++++++++++++++++++++++++-
>   src/base/conf.h  |   2 ++
>   2 files changed, 29 insertions(+), 1 deletions(-)
>
>
> Querying the DNS can potentially be very slow, especially in the case when the
> DNS servers are not responding e.g. due to a misconfiguration. Therefore, we
> instead use gethostname() + getdomainname() to build the fully qualified 
> domain
> name (FQDN) using locally stored information.
>
> The result from getdomainname() may not always be accurate so the long-term
> solution is probably to introduce a separate process/thread that can query the
> DNS in the background.
>
> diff --git a/src/base/conf.cc b/src/base/conf.cc
> --- a/src/base/conf.cc
> +++ b/src/base/conf.cc
> @@ -99,7 +99,33 @@ void Conf::PthreadOnceInitRoutine() {
>     if (instance_ == nullptr) osaf_abort(0);
>   }
>   
> -std::string Conf::GetFullyQualifiedDomainName(
> +std::string Conf::GetFullyQualifiedDomainName(const std::string&) {
> +  char host_name[HOST_NAME_MAX + 1];
> +  char domain_name[HOST_NAME_MAX + 1];
> +  if (gethostname(host_name, sizeof(host_name)) == 0) {
> +    host_name[sizeof(host_name) - 1] = '\0';
> +  } else {
> +    LOG_ER("gethostname() failed, errno=%d", errno);
> +    host_name[0] = '\0';
> +  }
> +  if (getdomainname(domain_name, sizeof(domain_name)) == 0) {
> +    domain_name[sizeof(domain_name) - 1] = '\0';
> +    if (strcmp(domain_name, "(none)") == 0) domain_name[0] = '\0';
> +  } else {
> +    LOG_ER("getdomainname() failed, errno=%d", errno);
> +    domain_name[0] = '\0';
> +  }
> +  std::string fqdn{host_name};
> +  if (domain_name[0] != '\0') {
> +    if (!fqdn.empty()) fqdn += ".";
> +    fqdn += domain_name;
> +  }
> +  return fqdn;
> +}
> +
> +// Currently not used - we need to introduce a background thread for querying
> +// the DNS, which can potentially be very slow.
> +std::string Conf::GetFullyQualifiedDomainNameUsingDns(
>       const std::string& short_host_name) {
>     char host[NI_MAXHOST];
>     std::string fqdn{short_host_name};
> diff --git a/src/base/conf.h b/src/base/conf.h
> --- a/src/base/conf.h
> +++ b/src/base/conf.h
> @@ -86,6 +86,8 @@ class Conf {
>     static void PthreadOnceInitRoutine();
>     static std::string GetFullyQualifiedDomainName(
>         const std::string& short_host_name);
> +  static std::string GetFullyQualifiedDomainNameUsingDns(
> +      const std::string& short_host_name);
>     static std::string GetNodeName(const std::string& short_host_name);
>     static std::string GetShortHostName();
>     static std::string ReadFile(const std::string& path_name,


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to