diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2020-07-14 21:21:58 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2020-07-14 21:21:58 +0100 |
commit | c920fdba39480989cb5f1af3cc63acccef021b54 (patch) | |
tree | a19a5c8002b47dfc1320b46e83aea052bd4c21d5 /util | |
parent | 8bfa25a46ff1082f75e7052875b5d435119dcf49 (diff) | |
parent | 0d3a8f32b1e0eca279da1b0cc793efc7250c3daf (diff) | |
download | qemu-c920fdba39480989cb5f1af3cc63acccef021b54.zip qemu-c920fdba39480989cb5f1af3cc63acccef021b54.tar.gz qemu-c920fdba39480989cb5f1af3cc63acccef021b54.tar.bz2 |
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2020-07-13-tag' into staging
qemu-ga patch queue for hard-freeze
* fix erroneously reporting stale hostname in guest-get-host-name
* fix regression where guest-shutdown asserts when called
* fix race condition with guest-fs-freeze/thaw on w32
# gpg: Signature made Tue 14 Jul 2020 05:47:11 BST
# gpg: using RSA key CEACC9E15534EBABB82D3FA03353C9CEF108B584
# gpg: issuer "mdroth@linux.vnet.ibm.com"
# gpg: Good signature from "Michael Roth <flukshun@gmail.com>" [full]
# gpg: aka "Michael Roth <mdroth@utexas.edu>" [full]
# gpg: aka "Michael Roth <mdroth@linux.vnet.ibm.com>" [full]
# Primary key fingerprint: CEAC C9E1 5534 EBAB B82D 3FA0 3353 C9CE F108 B584
* remotes/mdroth/tags/qga-pull-2020-07-13-tag:
qga: Use qemu_get_host_name() instead of g_get_host_name()
util: Introduce qemu_get_host_name()
qga: fix assert regression on guest-shutdown
qga-win: Fix QGA VSS Provider service stop failure
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/oslib-posix.c | 35 | ||||
-rw-r--r-- | util/oslib-win32.c | 13 |
2 files changed, 48 insertions, 0 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 72907d4..e60aea8 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -794,3 +794,38 @@ void sigaction_invoke(struct sigaction *action, } action->sa_sigaction(info->ssi_signo, &si, NULL); } + +#ifndef HOST_NAME_MAX +# ifdef _POSIX_HOST_NAME_MAX +# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX +# else +# define HOST_NAME_MAX 255 +# endif +#endif + +char *qemu_get_host_name(Error **errp) +{ + long len = -1; + g_autofree char *hostname = NULL; + +#ifdef _SC_HOST_NAME_MAX + len = sysconf(_SC_HOST_NAME_MAX); +#endif /* _SC_HOST_NAME_MAX */ + + if (len < 0) { + len = HOST_NAME_MAX; + } + + /* Unfortunately, gethostname() below does not guarantee a + * NULL terminated string. Therefore, allocate one byte more + * to be sure. */ + hostname = g_new0(char, len + 1); + + if (gethostname(hostname, len) < 0) { + error_setg_errno(errp, errno, + "cannot get hostname"); + return NULL; + } + + return g_steal_pointer(&hostname); +} diff --git a/util/oslib-win32.c b/util/oslib-win32.c index e9b14ab..3b49d27 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -808,3 +808,16 @@ bool qemu_write_pidfile(const char *filename, Error **errp) } return true; } + +char *qemu_get_host_name(Error **errp) +{ + wchar_t tmp[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD size = G_N_ELEMENTS(tmp); + + if (GetComputerNameW(tmp, &size) == 0) { + error_setg_win32(errp, GetLastError(), "failed close handle"); + return NULL; + } + + return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL); +} |