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

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