diff options
author | Sebastien Martini <seb@dbzteam.org> | 2010-07-27 16:32:02 +0200 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2010-07-27 16:32:02 +0200 |
commit | d87b2cdd62c232eef7a669ccc006161aaea66db4 (patch) | |
tree | b5fc34ec213c54666e18394b1874f459e97206ee /python3/pyinotify.py | |
parent | 2b156d82abad209bbd7470366a9c9ca1564b7659 (diff) | |
download | pyinotify-d87b2cdd62c232eef7a669ccc006161aaea66db4.tar.gz |
Modified loading mechanism of the libc (following issues reported
by przemyslaw.wrzos@calyptech.com).
Diffstat (limited to 'python3/pyinotify.py')
-rwxr-xr-x | python3/pyinotify.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/python3/pyinotify.py b/python3/pyinotify.py index d39638a..5cd6831 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -47,9 +47,10 @@ class UnsupportedPythonVersionError(PyinotifyError): 'at least Python 3.0') % version) -class UnsupportedLibcVersionError(PyinotifyError): +class LibcError(PyinotifyError): """ - Raised on unsupported libc versions. + Raised when libc couldn't be loaded or when inotify functions werent + provided. """ def __init__(self): err = 'libc does not provide required inotify support' @@ -100,17 +101,32 @@ COMPATIBILITY_MODE = False # Load libc -LIBC = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) +LIBC = None def strerrno(): code = ctypes.get_errno() return '%s (%s)' % (os.strerror(code), errno.errorcode[code]) -# Check that libc has needed functions inside. -if (not hasattr(LIBC, 'inotify_init') or - not hasattr(LIBC, 'inotify_add_watch') or - not hasattr(LIBC, 'inotify_rm_watch')): - raise UnsupportedLibcVersionError() +def load_libc(): + global LIBC + + l = None + try: + l = ctypes.util.find_library('c') + except OSError as err: + pass # Will attemp to load it with None anyway. + except IOError as err: + pass + + LIBC = ctypes.CDLL(l, use_errno=True) + + # Check that libc has needed functions inside. + if (not hasattr(LIBC, 'inotify_init') or + not hasattr(LIBC, 'inotify_add_watch') or + not hasattr(LIBC, 'inotify_rm_watch')): + raise LibcError() + +load_libc() class PyinotifyLogger(logging.Logger): |