hi guys

Found an infinite wait (blocking read) in contrib/collectd_unixsock.py
which happens when an unknown identifier is requested using getval()
now the method raises a KeyError exception

peter

-- 
:: e n d i a n
:: open source - open minds

:: peter warasin
:: http://www.endian.com   :: pe...@endian.com
commit cb922116216b9f5879d822e9fe7fbc06a20cfb3c
Author: Peter Warasin <pe...@endian.com>
Date:   Mon Jun 27 16:19:45 2011 +0200

    raise exception rather than wait infinitely if identifier is unknown
    
    raise a KeyError if getval() or getthreshold() unixsock returns replies
    an error because of request of an unknown identifier

diff --git a/contrib/collectd_unixsock.py b/contrib/collectd_unixsock.py
index ebe549c..5e6ec70 100644
--- a/contrib/collectd_unixsock.py
+++ b/contrib/collectd_unixsock.py
@@ -67,8 +67,9 @@ class Collectd():
         """
         numvalues = self._cmd('GETTHRESHOLD "%s"' % identifier)
         lines = []
-        if numvalues:
-            lines = self._readlines(numvalues)
+        if not numvalues or numvalues < 0:
+            raise KeyError("Identifier '%s' not found" % identifier)
+        lines = self._readlines(numvalues)
         return lines
 
     def getval(self, identifier, flush_after=True):
@@ -82,8 +83,9 @@ class Collectd():
         """
         numvalues = self._cmd('GETVAL "%s"' % identifier)
         lines = []
-        if numvalues:
-            lines = self._readlines(numvalues)
+        if not numvalues or numvalues < 0:
+            raise KeyError("Identifier '%s' not found" % identifier)
+        lines = self._readlines(numvalues)
         if flush_after:
             self.flush(identifiers=[identifier])
         return lines
_______________________________________________
collectd mailing list
collectd@verplant.org
http://mailman.verplant.org/listinfo/collectd

Reply via email to