Re: [libvirt] [PATCHv3 5/6] virsh: Register and unregister the close callback also in cmdConnect

2013-04-01 Thread Eric Blake
On 03/31/2013 10:20 AM, Peter Krempa wrote:
 This patch improves the error message after disconnecting from the
 hypervisor and adds the close callback operations required not to leak
 the callback reference.
 ---
  tools/virsh.c | 22 --
  1 file changed, 16 insertions(+), 6 deletions(-)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv3 5/6] virsh: Register and unregister the close callback also in cmdConnect

2013-03-31 Thread Peter Krempa
This patch improves the error message after disconnecting from the
hypervisor and adds the close callback operations required not to leak
the callback reference.
---
 tools/virsh.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index a43c236..a6e6eec 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -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;
+}
+
+if (virConnectRegisterCloseCallback(ctl-conn, vshCatchDisconnect,
+NULL, NULL)  0)
+vshError(ctl, %s, _(Unable to register disconnect callback));

-return !!ctl-conn;
+return true;
 }


-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list