[Libvir] What is the Difference Between virConnCopyLastError and virCopyLastError?

Richard W.M. Jones rjones at redhat.com
Thu Apr 10 15:39:40 UTC 2008


On Thu, Apr 10, 2008 at 02:56:36PM +0530, ajishrao wrote:
> 3. If virConnectOpen/virConnectOpenReadOnly fails which api should be
> called to know the error code?

You might find some example code useful.  Look at the definition of
CHECK_ERROR macro, used here:

  http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=8c1b14506d91;file=libvirt/libvirt_c.c
(eg line 63)

and defined here:

  http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=a5bc5f747f2c;file=libvirt/libvirt_c_prologue.c
(line 45)

and the _raise_virterror function which gets the virterror defined
here:

  http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=6fe1e50a49db;file=libvirt/libvirt_c_epilogue.c
(line 66)

  errp = conn ? virConnGetLastError (conn) : virGetLastError ();

Note that actually copying the virterror may not be such a good idea.
The lifetime of that structure and the strings / pointers contained
within it is a little bit undefined, and the virCopy* functions don't
do a deep copy IIRC.  So you should take copies of anything you need
yourself, and make sure you don't refer to the conn/dom/net structure
fields if you can possibly avoid it.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top




More information about the libvir-list mailing list