[libvirt] [PATCH] util: Make getaddrinfo failure nonfatal in virGetHostname

Setting a hostname that cannot be resolved is not the best configuration but since virGetHostname only calls getaddrinfo to get host's canonical name and we do not fail if the returned canonical name is NULL or "localhost", there is no reason why we should fail if getaddrinfo itself fails. --- src/util/util.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/util.c b/src/util/util.c index 1ff287d..fd4d7fa 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -1858,10 +1858,10 @@ char *virIndexToDiskName(int idx, const char *prefix) * try to resolve this to a fully-qualified name. Therefore we pass it * to getaddrinfo(). There are two possible responses: * a) getaddrinfo() resolves to a FQDN - return the FQDN - * b) getaddrinfo() resolves to localhost - in this case, the data we got - * from gethostname() is actually more useful than what we got from - * getaddrinfo(). Return the value from gethostname() and hope for - * the best. + * b) getaddrinfo() files or resolves to localhost - in this case, the + * data we got from gethostname() is actually more useful than what + * we got from getaddrinfo(). Return the value from gethostname() + * and hope for the best. */ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) { @@ -1897,10 +1897,10 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) hints.ai_family = AF_UNSPEC; r = getaddrinfo(hostname, NULL, &hints, &info); if (r != 0) { - virUtilError(VIR_ERR_INTERNAL_ERROR, - _("getaddrinfo failed for '%s': %s"), - hostname, gai_strerror(r)); - return NULL; + VIR_WARN("getaddrinfo failed for '%s': %s", + hostname, gai_strerror(r)); + result = strdup(hostname); + goto check_and_return; } /* Tell static analyzers about getaddrinfo semantics. */ -- 1.7.7

On 10/13/2011 08:41 AM, Jiri Denemark wrote:
Setting a hostname that cannot be resolved is not the best configuration but since virGetHostname only calls getaddrinfo to get host's canonical name and we do not fail if the returned canonical name is NULL or "localhost", there is no reason why we should fail if getaddrinfo itself fails. --- src/util/util.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c index 1ff287d..fd4d7fa 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -1858,10 +1858,10 @@ char *virIndexToDiskName(int idx, const char *prefix) * try to resolve this to a fully-qualified name. Therefore we pass it * to getaddrinfo(). There are two possible responses: * a) getaddrinfo() resolves to a FQDN - return the FQDN - * b) getaddrinfo() resolves to localhost - in this case, the data we got - * from gethostname() is actually more useful than what we got from - * getaddrinfo(). Return the value from gethostname() and hope for - * the best. + * b) getaddrinfo() files or resolves to localhost - in this case, the
s/files/fails/ ACK with typo fixed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Oct 13, 2011 at 08:47:06 -0600, Eric Blake wrote:
On 10/13/2011 08:41 AM, Jiri Denemark wrote:
Setting a hostname that cannot be resolved is not the best configuration but since virGetHostname only calls getaddrinfo to get host's canonical name and we do not fail if the returned canonical name is NULL or "localhost", there is no reason why we should fail if getaddrinfo itself fails. --- src/util/util.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c index 1ff287d..fd4d7fa 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -1858,10 +1858,10 @@ char *virIndexToDiskName(int idx, const char *prefix) * try to resolve this to a fully-qualified name. Therefore we pass it * to getaddrinfo(). There are two possible responses: * a) getaddrinfo() resolves to a FQDN - return the FQDN - * b) getaddrinfo() resolves to localhost - in this case, the data we got - * from gethostname() is actually more useful than what we got from - * getaddrinfo(). Return the value from gethostname() and hope for - * the best. + * b) getaddrinfo() files or resolves to localhost - in this case, the
s/files/fails/
ACK with typo fixed.
Heh, I wrote "filas" and fixed it to the closest word instead of the right one :-) Moreover, I forgot to squash the fix in so I pushed it as a separate commit later. Jirka
participants (2)
-
Eric Blake
-
Jiri Denemark