mirror of https://github.com/xemu-project/xemu.git
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 -----BEGIN PGP SIGNATURE----- iQFOBAABCgA4FiEEzqzJ4VU066u4LT+gM1PJzvEItYQFAl8NOM8aHG1kcm90aEBs aW51eC52bmV0LmlibS5jb20ACgkQM1PJzvEItYQaMAf/Y7A1EnYmn66r08desn6H cAw6+RKzsDBkMdmqihv7FYc6T9ncT9MkFRFDj26nBuspdcA5ZJyks/yPF8WVY5Df D32bIeOjzj9sdb/4amJFgov69LCSD4Tu4SdWbqIhDdNvYAjbQvocx6w52knmqKdD ncjVvTA4N6kJ/MEDTrNApU6HneuFgRyACMcrjfVkOSUH3lfTlBeAO0WuslLmQZ1e vjropA61JDA62Te2zr1ZiH/PLeS4IFh3fHbOCSYywOagKB3bADqeUp1W8Yp9XaXG tdN2VQaCzES+aleZCh9Gqy16Xcu0hotNjjEmHYsYAxRzMrsgAokfOpWm1uFkfUmv bw== =BzOm -----END PGP SIGNATURE----- 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>
This commit is contained in:
commit
c920fdba39
|
@ -655,4 +655,14 @@ static inline void qemu_reset_optind(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* qemu_get_host_name:
|
||||
* @errp: Error object
|
||||
*
|
||||
* Operating system agnostic way of querying host name.
|
||||
*
|
||||
* Returns allocated hostname (caller should free), NULL on failure.
|
||||
*/
|
||||
char *qemu_get_host_name(Error **errp);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -531,7 +531,11 @@ static int send_response(GAState *s, const QDict *rsp)
|
|||
QString *payload_qstr, *response_qstr;
|
||||
GIOStatus status;
|
||||
|
||||
g_assert(rsp && s->channel);
|
||||
g_assert(s->channel);
|
||||
|
||||
if (!rsp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
payload_qstr = qobject_to_json(QOBJECT(rsp));
|
||||
if (!payload_qstr) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <comdef.h>
|
||||
#include <comutil.h>
|
||||
#include <sddl.h>
|
||||
#include <winsvc.h>
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
|
@ -509,26 +510,32 @@ namespace _com_util
|
|||
}
|
||||
}
|
||||
|
||||
/* Stop QGA VSS provider service from COM+ Application Admin Catalog */
|
||||
|
||||
/* Stop QGA VSS provider service using Winsvc API */
|
||||
STDAPI StopService(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
COMInitializer initializer;
|
||||
COMPointer<IUnknown> pUnknown;
|
||||
COMPointer<ICOMAdminCatalog2> pCatalog;
|
||||
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
SC_HANDLE service = NULL;
|
||||
|
||||
int count = 0;
|
||||
if (!manager) {
|
||||
errmsg(E_FAIL, "Failed to open service manager");
|
||||
hr = E_FAIL;
|
||||
goto out;
|
||||
}
|
||||
service = OpenService(manager, QGA_PROVIDER_NAME, SC_MANAGER_ALL_ACCESS);
|
||||
|
||||
chk(QGAProviderFind(QGAProviderCount, (void *)&count));
|
||||
if (count) {
|
||||
chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER,
|
||||
IID_IUnknown, (void **)pUnknown.replace()));
|
||||
chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog2,
|
||||
(void **)pCatalog.replace()));
|
||||
chk(pCatalog->ShutdownApplication(_bstr_t(QGA_PROVIDER_LNAME)));
|
||||
if (!service) {
|
||||
errmsg(E_FAIL, "Failed to open service");
|
||||
hr = E_FAIL;
|
||||
goto out;
|
||||
}
|
||||
if (!(ControlService(service, SERVICE_CONTROL_STOP, NULL))) {
|
||||
errmsg(E_FAIL, "Failed to stop service");
|
||||
hr = E_FAIL;
|
||||
}
|
||||
|
||||
out:
|
||||
CloseServiceHandle(service);
|
||||
CloseServiceHandle(manager);
|
||||
return hr;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue