Commit 0d3a8f32 authored by Michal Privoznik's avatar Michal Privoznik Committed by Michael Roth
Browse files

qga: Use qemu_get_host_name() instead of g_get_host_name()

Problem with g_get_host_name() is that on the first call it saves
the hostname into a global variable and from then on, every
subsequent call returns the saved hostname. Even if the hostname
changes. This doesn't play nicely with guest agent, because if
the hostname is acquired before the guest is set up (e.g. on the
first boot, or before DHCP) we will report old, invalid hostname.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1845127



Signed-off-by: default avatarMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: default avatarMichael Roth <mdroth@linux.vnet.ibm.com>
parent e47f4765
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -515,11 +515,20 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
GuestHostName *qmp_guest_get_host_name(Error **errp)
{
    GuestHostName *result = NULL;
    gchar const *hostname = g_get_host_name();
    if (hostname != NULL) {
        result = g_new0(GuestHostName, 1);
        result->host_name = g_strdup(hostname);
    g_autofree char *hostname = qemu_get_host_name(errp);

    /*
     * We want to avoid using g_get_host_name() because that
     * caches the result and we wouldn't reflect changes in the
     * host name.
     */

    if (!hostname) {
        hostname = g_strdup("localhost");
    }

    result = g_new0(GuestHostName, 1);
    result->host_name = g_steal_pointer(&hostname);
    return result;
}