Skip to content

Commit

Permalink
[inotify] Simplify libc loading (#776)
Browse files Browse the repository at this point in the history
libc is used by the Python interpreter itself, thus dlopen(NULL) is sufficient,
no need to load the library again.

Co-authored-by: Mikhail T <Mikhail.Teterin@BNYMellon.com>
  • Loading branch information
UnitedMarsupials and Mikhail T committed May 4, 2021
1 parent 7728a45 commit 1415238
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions src/watchdog/observers/inotify_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,7 @@
from ctypes import c_int, c_char_p, c_uint32
from watchdog.utils import UnsupportedLibc


def _load_libc():
libc_path = None
try:
libc_path = ctypes.util.find_library('c')
except (OSError, RuntimeError):
# Note: find_library will on some platforms raise these undocumented
# errors, e.g.on android OSError "No usable temporary directory found"
# will be raised.
pass

if libc_path is not None:
return ctypes.CDLL(libc_path)

# Fallbacks
try:
return ctypes.CDLL('libc.so')
except OSError:
pass

try:
return ctypes.CDLL('libc.so.6')
except OSError:
pass

# uClibc
try:
return ctypes.CDLL('libc.so.0')
except OSError as err:
raise err


libc = _load_libc()
libc = ctypes.CDLL(None)

if not hasattr(libc, 'inotify_init') or \
not hasattr(libc, 'inotify_add_watch') or \
Expand Down

0 comments on commit 1415238

Please sign in to comment.