[libvirt] [PATCH] python: don't mask libvirt errors

A user reported this crash when using python bindings: File "/home/nox/workspace/NOX/src/NOX/hooks.py", line 134, in trigger hook.trigger(event) File "/home/nox/workspace/NOX/src/NOX/hooks.py", line 33, in trigger self.handlers[event]() File "/home/nox/workspace/NOX/hooks/volatility.py", line 81, in memory_dump for block in Memory(self.ctx): File "/home/see/workspace/NOX/src/NOX/lib/libtools.py", line 179, in next libvirt.VIR_MEMORY_PHYSICAL) File "/usr/lib/python2.7/dist-packages/libvirt.py", line 1759, in memoryPeek ret = libvirtmod.virDomainMemoryPeek(self._o, start, size, flags) SystemError: error return without exception set In the python bindings, returning NULL makes python think an exception was thrown, while returning the None object lets the wrappers know that a libvirt error exists. Reported by Nox DaFox, fix suggested by Dan Berrange. * python/libvirt-override.c (libvirt_virDomainBlockPeek) (libvirt_virDomainMemoryPeek): Return python's None object, so wrapper knows to check libvirt error. --- python/libvirt-override.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 8b41dff..65e8c69 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -5763,8 +5763,10 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, c_retval = virDomainBlockPeek(domain, disk, offset, size, buf, flags); LIBVIRT_END_ALLOW_THREADS; - if (c_retval < 0) + if (c_retval < 0) { + py_retval = VIR_PY_NONE; goto cleanup; + } py_retval = PyString_FromStringAndSize(buf, size); @@ -5798,8 +5800,10 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, c_retval = virDomainMemoryPeek(domain, start, size, buf, flags); LIBVIRT_END_ALLOW_THREADS; - if (c_retval < 0) + if (c_retval < 0) { + py_retval = VIR_PY_NONE; goto cleanup; + } py_retval = PyString_FromStringAndSize(buf, size); -- 1.7.11.4

On 08/31/12 19:10, Eric Blake wrote:
A user reported this crash when using python bindings:
File "/home/nox/workspace/NOX/src/NOX/hooks.py", line 134, in trigger hook.trigger(event) File "/home/nox/workspace/NOX/src/NOX/hooks.py", line 33, in trigger self.handlers[event]() File "/home/nox/workspace/NOX/hooks/volatility.py", line 81, in memory_dump for block in Memory(self.ctx): File "/home/see/workspace/NOX/src/NOX/lib/libtools.py", line 179, in next libvirt.VIR_MEMORY_PHYSICAL) File "/usr/lib/python2.7/dist-packages/libvirt.py", line 1759, in memoryPeek ret = libvirtmod.virDomainMemoryPeek(self._o, start, size, flags) SystemError: error return without exception set
In the python bindings, returning NULL makes python think an exception was thrown, while returning the None object lets the wrappers know that a libvirt error exists.
Reported by Nox DaFox, fix suggested by Dan Berrange.
* python/libvirt-override.c (libvirt_virDomainBlockPeek) (libvirt_virDomainMemoryPeek): Return python's None object, so wrapper knows to check libvirt error. --- python/libvirt-override.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
ACK. Peter

On 08/31/2012 03:05 PM, Peter Krempa wrote:
On 08/31/12 19:10, Eric Blake wrote:
A user reported this crash when using python bindings:
In the python bindings, returning NULL makes python think an exception was thrown, while returning the None object lets the wrappers know that a libvirt error exists.
Reported by Nox DaFox, fix suggested by Dan Berrange.
* python/libvirt-override.c (libvirt_virDomainBlockPeek) (libvirt_virDomainMemoryPeek): Return python's None object, so wrapper knows to check libvirt error. --- python/libvirt-override.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
ACK.
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Peter Krempa