Ejemplo n.º 1
0
import os
import errno
import struct
import threading
import ctypes
import ctypes.util
from functools import reduce
from ctypes import c_int, c_char_p, c_uint32
from watchdog.utils import UnsupportedLibc

libc = ctypes.CDLL(None)

if not hasattr(libc, 'inotify_init') or \
        not hasattr(libc, 'inotify_add_watch') or \
        not hasattr(libc, 'inotify_rm_watch'):
    raise UnsupportedLibc("Unsupported libc version found: %s" % libc._name)

inotify_add_watch = ctypes.CFUNCTYPE(c_int,
                                     c_int,
                                     c_char_p,
                                     c_uint32,
                                     use_errno=True)(
                                         ("inotify_add_watch", libc))

inotify_rm_watch = ctypes.CFUNCTYPE(c_int, c_int, c_uint32,
                                    use_errno=True)(("inotify_rm_watch", libc))

inotify_init = ctypes.CFUNCTYPE(c_int, use_errno=True)(("inotify_init", libc))


class InotifyConstants:
Ejemplo n.º 2
0
    except (OSError, IOError):
        pass

    if libc_path is not None:
        return ctypes.CDLL(libc_path)
    try:
        return ctypes.CDLL('libc.so')
    except (OSError, IOError):
        return ctypes.CDLL('libc.so.6')


libc = _load_libc()
if not has_attribute(libc, 'inotify_init') or not has_attribute(
        libc, 'inotify_add_watch') or not has_attribute(
            libc, 'inotify_rm_watch'):
    raise UnsupportedLibc('Unsupported libc version found: %s' % libc._name)
inotify_add_watch = ctypes.CFUNCTYPE(c_int,
                                     c_int,
                                     c_char_p,
                                     c_uint32,
                                     use_errno=True)(
                                         ('inotify_add_watch', libc))
inotify_rm_watch = ctypes.CFUNCTYPE(c_int, c_int, c_uint32,
                                    use_errno=True)(('inotify_rm_watch', libc))
inotify_init = ctypes.CFUNCTYPE(c_int, use_errno=True)(('inotify_init', libc))


class InotifyConstants(object):
    IN_ACCESS = 1
    IN_MODIFY = 2
    IN_ATTRIB = 4