summaryrefslogtreecommitdiff
path: root/libvirtaio.py
diff options
context:
space:
mode:
authorPhilipp Hahn <hahn@univention.de>2020-04-27 09:44:57 +0200
committerPhilipp Hahn <hahn@univention.de>2020-07-27 13:24:36 +0200
commitcfcf988a98b66f350cfbc9af880eacb7c2aebe07 (patch)
tree8c36b4faed2bc56405dbb88a176236cca844482b /libvirtaio.py
parentb595e59b48d8a740b8033a4ba289d8c94be56f98 (diff)
downloadlibvirt-python-cfcf988a98b66f350cfbc9af880eacb7c2aebe07.tar.gz
libvirtaio: Fix return types of callback
libvirt defines the signature for the callback functions, e.g. the functions for remove() must return -1 on error and 0 on success. Raising an exception violates that contract. _remove_timeout() did not explicitly handle a double-remove and implicitly passed on the exception. update() expects no return value, so remove the pointless return to pass on None. Signed-off-by: Philipp Hahn <hahn@univention.de>
Diffstat (limited to 'libvirtaio.py')
-rw-r--r--libvirtaio.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/libvirtaio.py b/libvirtaio.py
index 328e6f2..f1811c1 100644
--- a/libvirtaio.py
+++ b/libvirtaio.py
@@ -370,13 +370,13 @@ class virEventAsyncIOImpl(object):
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateHandleFunc
'''
self.log.debug('update_handle(watch=%d, event=%d)', watch, event)
- return self.callbacks[watch].update(event=event)
+ self.callbacks[watch].update(event=event)
def _remove_handle(self, watch):
'''Unregister a callback from a file handle.
:param int watch: file descriptor watch to stop listening on
- :returns: None (see source for explanation)
+ :returns: -1 on error, 0 on success
.. seealso::
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveHandleFunc
@@ -386,12 +386,13 @@ class virEventAsyncIOImpl(object):
callback = self.callbacks.pop(watch)
except KeyError as err:
self.log.warning('remove_handle(): no such handle: %r', err.args[0])
- raise
+ return -1
fd = callback.descriptor.fd
assert callback is self.descriptors[fd].remove_handle(watch)
if len(self.descriptors[fd].callbacks) == 0:
del self.descriptors[fd]
callback.close()
+ return 0
def _add_timeout(self, timeout, cb, opaque):
'''Register a callback for a timer event
@@ -425,20 +426,25 @@ class virEventAsyncIOImpl(object):
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateTimeoutFunc
'''
self.log.debug('update_timeout(timer=%d, timeout=%d)', timer, timeout)
- return self.callbacks[timer].update(timeout=timeout)
+ self.callbacks[timer].update(timeout=timeout)
def _remove_timeout(self, timer):
'''Unregister a callback for a timer
:param int timer: the timer to remove
- :returns: None (see source for explanation)
+ :returns: -1 on error, 0 on success
.. seealso::
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc
'''
self.log.debug('remove_timeout(timer=%d)', timer)
- callback = self.callbacks.pop(timer)
+ try:
+ callback = self.callbacks.pop(timer)
+ except KeyError as err:
+ self.log.warning('remove_timeout(): no such timeout: %r', err.args[0])
+ return -1
callback.close()
+ return 0
_current_impl = None