Blame SOURCES/kvm-qga-Use-qemu_get_host_name-instead-of-g_get_host_nam.patch

a19a21
From c5f90436555d7ab2c1c28bf1cfdb5f5f8ca97816 Mon Sep 17 00:00:00 2001
a19a21
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
a19a21
Date: Thu, 24 Dec 2020 12:53:04 -0500
a19a21
Subject: [PATCH 4/5] qga: Use qemu_get_host_name() instead of
a19a21
 g_get_host_name()
a19a21
MIME-Version: 1.0
a19a21
Content-Type: text/plain; charset=UTF-8
a19a21
Content-Transfer-Encoding: 8bit
a19a21
a19a21
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
a19a21
Message-id: <20201224125304.62697-4-marcandre.lureau@redhat.com>
a19a21
Patchwork-id: 100500
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 3/3] qga: Use qemu_get_host_name() instead of g_get_host_name()
a19a21
Bugzilla: 1910326
a19a21
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
a19a21
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
a19a21
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
a19a21
a19a21
From: Michal Privoznik <mprivozn@redhat.com>
a19a21
a19a21
Problem with g_get_host_name() is that on the first call it saves
a19a21
the hostname into a global variable and from then on, every
a19a21
subsequent call returns the saved hostname. Even if the hostname
a19a21
changes. This doesn't play nicely with guest agent, because if
a19a21
the hostname is acquired before the guest is set up (e.g. on the
a19a21
first boot, or before DHCP) we will report old, invalid hostname.
a19a21
a19a21
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1845127
a19a21
a19a21
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
a19a21
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
a19a21
Cc: qemu-stable@nongnu.org
a19a21
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
a19a21
a19a21
(cherry picked from commit 0d3a8f32b1e0eca279da1b0cc793efc7250c3daf)
a19a21
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
a19a21
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a19a21
---
a19a21
 qga/commands.c | 17 +++++++++++++----
a19a21
 1 file changed, 13 insertions(+), 4 deletions(-)
a19a21
a19a21
diff --git a/qga/commands.c b/qga/commands.c
a19a21
index 43c323ceada..93bed292d08 100644
a19a21
--- a/qga/commands.c
a19a21
+++ b/qga/commands.c
a19a21
@@ -502,11 +502,20 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
a19a21
 GuestHostName *qmp_guest_get_host_name(Error **errp)
a19a21
 {
a19a21
     GuestHostName *result = NULL;
a19a21
-    gchar const *hostname = g_get_host_name();
a19a21
-    if (hostname != NULL) {
a19a21
-        result = g_new0(GuestHostName, 1);
a19a21
-        result->host_name = g_strdup(hostname);
a19a21
+    g_autofree char *hostname = qemu_get_host_name(errp);
a19a21
+
a19a21
+    /*
a19a21
+     * We want to avoid using g_get_host_name() because that
a19a21
+     * caches the result and we wouldn't reflect changes in the
a19a21
+     * host name.
a19a21
+     */
a19a21
+
a19a21
+    if (!hostname) {
a19a21
+        hostname = g_strdup("localhost");
a19a21
     }
a19a21
+
a19a21
+    result = g_new0(GuestHostName, 1);
a19a21
+    result->host_name = g_steal_pointer(&hostname);
a19a21
     return result;
a19a21
 }
a19a21
 
a19a21
-- 
a19a21
2.27.0
a19a21