提交 f1409fa7 编写于 作者: J Jiri Denemark

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.
上级 bf7676af
...@@ -1858,10 +1858,10 @@ char *virIndexToDiskName(int idx, const char *prefix) ...@@ -1858,10 +1858,10 @@ char *virIndexToDiskName(int idx, const char *prefix)
* try to resolve this to a fully-qualified name. Therefore we pass it * try to resolve this to a fully-qualified name. Therefore we pass it
* to getaddrinfo(). There are two possible responses: * to getaddrinfo(). There are two possible responses:
* a) getaddrinfo() resolves to a FQDN - return the FQDN * a) getaddrinfo() resolves to a FQDN - return the FQDN
* b) getaddrinfo() resolves to localhost - in this case, the data we got * b) getaddrinfo() files or resolves to localhost - in this case, the
* from gethostname() is actually more useful than what we got from * data we got from gethostname() is actually more useful than what
* getaddrinfo(). Return the value from gethostname() and hope for * we got from getaddrinfo(). Return the value from gethostname()
* the best. * and hope for the best.
*/ */
char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
{ {
...@@ -1897,10 +1897,10 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) ...@@ -1897,10 +1897,10 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
r = getaddrinfo(hostname, NULL, &hints, &info); r = getaddrinfo(hostname, NULL, &hints, &info);
if (r != 0) { if (r != 0) {
virUtilError(VIR_ERR_INTERNAL_ERROR, VIR_WARN("getaddrinfo failed for '%s': %s",
_("getaddrinfo failed for '%s': %s"), hostname, gai_strerror(r));
hostname, gai_strerror(r)); result = strdup(hostname);
return NULL; goto check_and_return;
} }
/* Tell static analyzers about getaddrinfo semantics. */ /* Tell static analyzers about getaddrinfo semantics. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册