mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
hyperv: use GLib auto-cleanup in hypervDomainSendKey
Signed-off-by: Matt Coleman <matt@datto.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
d9c015ec2c
commit
e9a9707fa3
@ -2991,15 +2991,14 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
unsigned int holdtime, unsigned int *keycodes, int nkeycodes,
|
unsigned int holdtime, unsigned int *keycodes, int nkeycodes,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int result = -1;
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int keycode = 0;
|
int keycode = 0;
|
||||||
int *translatedKeycodes = NULL;
|
g_autofree int *translatedKeycodes = NULL;
|
||||||
hypervPrivate *priv = domain->conn->privateData;
|
hypervPrivate *priv = domain->conn->privateData;
|
||||||
char uuid_string[VIR_UUID_STRING_BUFLEN];
|
char uuid_string[VIR_UUID_STRING_BUFLEN];
|
||||||
char *selector = NULL;
|
g_autofree char *selector = NULL;
|
||||||
Msvm_ComputerSystem *computerSystem = NULL;
|
g_autoptr(Msvm_ComputerSystem) computerSystem = NULL;
|
||||||
Msvm_Keyboard *keyboard = NULL;
|
g_autoptr(Msvm_Keyboard) keyboard = NULL;
|
||||||
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
|
||||||
g_autoptr(hypervInvokeParamsList) params = NULL;
|
g_autoptr(hypervInvokeParamsList) params = NULL;
|
||||||
char keycodeStr[VIR_INT64_STR_BUFLEN];
|
char keycodeStr[VIR_INT64_STR_BUFLEN];
|
||||||
@ -3009,7 +3008,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
virUUIDFormat(domain->uuid, uuid_string);
|
virUUIDFormat(domain->uuid, uuid_string);
|
||||||
|
|
||||||
if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
|
if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
virBufferEscapeSQL(&query,
|
virBufferEscapeSQL(&query,
|
||||||
"ASSOCIATORS OF {Msvm_ComputerSystem.CreationClassName='Msvm_ComputerSystem',Name='%s'} "
|
"ASSOCIATORS OF {Msvm_ComputerSystem.CreationClassName='Msvm_ComputerSystem',Name='%s'} "
|
||||||
@ -3017,7 +3016,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
uuid_string);
|
uuid_string);
|
||||||
|
|
||||||
if (hypervGetWmiClass(Msvm_Keyboard, &keyboard) < 0)
|
if (hypervGetWmiClass(Msvm_Keyboard, &keyboard) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
translatedKeycodes = g_new0(int, nkeycodes);
|
translatedKeycodes = g_new0(int, nkeycodes);
|
||||||
|
|
||||||
@ -3031,7 +3030,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
if (keycode < 0) {
|
if (keycode < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Could not translate keycode"));
|
_("Could not translate keycode"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
translatedKeycodes[i] = keycode;
|
translatedKeycodes[i] = keycode;
|
||||||
}
|
}
|
||||||
@ -3049,13 +3048,13 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
Msvm_Keyboard_WmiInfo);
|
Msvm_Keyboard_WmiInfo);
|
||||||
|
|
||||||
if (!params)
|
if (!params)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0)
|
if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
|
if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* simulate holdtime by sleeping */
|
/* simulate holdtime by sleeping */
|
||||||
@ -3069,23 +3068,16 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
|
|||||||
Msvm_Keyboard_WmiInfo);
|
Msvm_Keyboard_WmiInfo);
|
||||||
|
|
||||||
if (!params)
|
if (!params)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0)
|
if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
|
if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(translatedKeycodes);
|
|
||||||
VIR_FREE(selector);
|
|
||||||
hypervFreeObject((hypervObject *)keyboard);
|
|
||||||
hypervFreeObject((hypervObject *)computerSystem);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user