mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
virsh: Register and unregister the close callback also in cmdConnect
This patch improves the error message after disconnecting from the hypervisor and adds the close callback operations required not to leak the callback reference. (cherry picked from commit 69ab07560a134e82e36b6391be3c806d3dbdb16c)
This commit is contained in:
parent
f4a7891e64
commit
3e13977c2e
@ -391,10 +391,14 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
if (ctl->conn) {
|
||||
int ret;
|
||||
if ((ret = virConnectClose(ctl->conn)) != 0) {
|
||||
vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
virConnectUnregisterCloseCallback(ctl->conn, vshCatchDisconnect);
|
||||
ret = virConnectClose(ctl->conn);
|
||||
if (ret < 0)
|
||||
vshError(ctl, "%s", _("Failed to disconnect from the hypervisor"));
|
||||
else if (ret > 0)
|
||||
vshError(ctl, "%s", _("One or more references were leaked after "
|
||||
"disconnect from the hypervisor"));
|
||||
ctl->conn = NULL;
|
||||
}
|
||||
|
||||
@ -411,10 +415,16 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
||||
ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
|
||||
ctl->readonly ? VIR_CONNECT_RO : 0);
|
||||
|
||||
if (!ctl->conn)
|
||||
if (!ctl->conn) {
|
||||
vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!ctl->conn;
|
||||
if (virConnectRegisterCloseCallback(ctl->conn, vshCatchDisconnect,
|
||||
NULL, NULL) < 0)
|
||||
vshError(ctl, "%s", _("Unable to register disconnect callback"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user