[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen stable-4.14] qga: Use qemu_get_host_name() instead of g_get_host_name()



commit 3ddb01cd149f9d2064f8ce2dff6a75b2e18b3cd2
Author:     Michal Privoznik <mprivozn@xxxxxxxxxx>
AuthorDate: Mon Jun 22 20:19:36 2020 +0200
Commit:     Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
CommitDate: Wed Sep 2 19:06:19 2020 -0500

    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: Michal Privoznik <mprivozn@xxxxxxxxxx>
    Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
    Cc: qemu-stable@xxxxxxxxxx
    Signed-off-by: Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
    (cherry picked from commit 0d3a8f32b1e0eca279da1b0cc793efc7250c3daf)
    Signed-off-by: Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
---
 qga/commands.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/qga/commands.c b/qga/commands.c
index efc8b90281..d3fec807c1 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -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;
 }
 
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#stable-4.14



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.