mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virutil: Do not use g_get_host_name() to obtain hostname
The problem is that g_get_host_name() caches the hostname in a thread local variable. Therefore, it doesn't reflect any subsequent hostname changes. While this might be acceptable for logs where the hostname is printed exactly once when the libvirtd starts up, it is not optimal for virGetHostnameImpl() which is what our public virConnectGetHostname() API calls. If the hostname at the moment of the first API invocation happens to start with "localhost" or contains a dot, then no further hostname changes will ever be reflected. This reverts 26d9748ff11, partially. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
2d91b1405d
commit
c2840e90ea
@ -475,11 +475,17 @@ static char *
|
||||
virGetHostnameImpl(bool quiet)
|
||||
{
|
||||
int r;
|
||||
const char *hostname;
|
||||
char *result = NULL;
|
||||
char hostname[HOST_NAME_MAX+1], *result = NULL;
|
||||
struct addrinfo hints, *info;
|
||||
|
||||
hostname = g_get_host_name();
|
||||
r = gethostname(hostname, sizeof(hostname));
|
||||
if (r == -1) {
|
||||
if (!quiet)
|
||||
virReportSystemError(errno,
|
||||
"%s", _("failed to determine host name"));
|
||||
return NULL;
|
||||
}
|
||||
NUL_TERMINATE(hostname);
|
||||
|
||||
if (STRPREFIX(hostname, "localhost") || strchr(hostname, '.')) {
|
||||
/* in this case, gethostname returned localhost (meaning we can't
|
||||
|
Loading…
x
Reference in New Issue
Block a user