On 9/29/20 5:10 PM, Ján Tomko wrote:
On a Tuesday in 2020, Peter Krempa wrote:
Move around some code so that we can get rid of the 'cleanup:' label.
Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
src/qemu/qemu_migration_cookie.c | 35 ++++++++++++++++----------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_migration_cookie.c
b/src/qemu/qemu_migration_cookie.c
index 124f61e3ea..a04b74f092 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -280,31 +280,30 @@ qemuMigrationCookieNew(const virDomainDef *def,
                      const char *origname)
{
   qemuMigrationCookiePtr mig = NULL;
-Â Â Â const char *name;
+Â Â Â unsigned char localHostUUID[VIR_UUID_BUFLEN];
+Â Â Â g_autofree char *localHostname = NULL;
-Â Â Â if (VIR_ALLOC(mig) < 0)
-Â Â Â Â Â Â Â goto error;
-
-Â Â Â if (origname)
-Â Â Â Â Â Â Â name = origname;
-Â Â Â else
-Â Â Â Â Â Â Â name = def->name;
-Â Â Â mig->name = g_strdup(name);
-Â Â Â memcpy(mig->uuid, def->uuid, VIR_UUID_BUFLEN);
+Â Â Â if (!(localHostname = virGetHostname()))
+Â Â Â Â Â Â Â return NULL;
-Â Â Â if (!(mig->localHostname = virGetHostname()))
-Â Â Â Â Â Â Â goto error;
Note that as of:
commit 26d9748ff114a060ee751959d108d062f737f5d9
   util: replace gethostname() with g_get_hostname()
the virGetHostname function always g_strdup's something.
Since you mentioned this, g_get_hostname() is horrible API as it caches
the host name on the first run and returns a const char * so there is no
way for callers to reflect on changing hostname. We had to drop it in
qemu-ga, because if qemu-ga was started before network was configured
then hostname change on DHCP wasn't being reflected. Hopefully, it is
not a problem for libvirt because we start after NICs are configured.
And nobody is really changing the hostname once a host is running, or
are they?
# hostname; virsh hostname ; hostname asdf; virsh hostname ; hostname
bart
bart
bart
asdf
Michal