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

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