Skip to content

Commit

Permalink
Merge 5472b90 into 542efdb
Browse files Browse the repository at this point in the history
  • Loading branch information
rev1si0n committed Jun 10, 2021
2 parents 542efdb + 5472b90 commit 342b2f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions iptc/ip4tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
_IFNAMSIZ = 16

_libc = find_libc()
_get_errno_loc = _libc.__errno_location
_get_errno_loc.restype = ct.POINTER(ct.c_int)
_malloc = _libc.malloc
_malloc.restype = ct.POINTER(ct.c_ubyte)
_malloc.argtypes = [ct.c_size_t]
Expand Down Expand Up @@ -1655,7 +1653,8 @@ def builtin_chain(self, chain):

def strerror(self):
"""Returns any pending iptables error from the previous operation."""
errno = _get_errno_loc()[0]
errno = ct.get_errno()
ct.set_errno(0)
if errno == 0:
return "libiptc version error"
return self._iptc.iptc_strerror(errno)
Expand Down
14 changes: 8 additions & 6 deletions iptc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,27 @@ def load_kernel(name, exc_if_failed=False):
def _do_find_library(name):
if '/' in name:
try:
return ctypes.CDLL(name, mode=ctypes.RTLD_GLOBAL)
return ctypes.CDLL(name, mode=ctypes.RTLD_GLOBAL, use_errno=True)
except Exception:
return None
p = ctypes.util.find_library(name)
if p:
lib = ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL)
lib = ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL, use_errno=True)
return lib

# probably we have been installed in a virtualenv
try:
lib = ctypes.CDLL(os.path.join(get_python_lib(), name),
mode=ctypes.RTLD_GLOBAL)
mode=ctypes.RTLD_GLOBAL,
use_errno=True)
return lib
except:
pass

for p in sys.path:
try:
lib = ctypes.CDLL(os.path.join(p, name), mode=ctypes.RTLD_GLOBAL)
lib = ctypes.CDLL(os.path.join(p, name), mode=ctypes.RTLD_GLOBAL,
use_errno=True)
return lib
except:
pass
Expand Down Expand Up @@ -121,12 +123,12 @@ def find_library(*names):
def find_libc():
lib = ctypes.util.find_library('c')
if lib is not None:
return ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
return ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL, use_errno=True)

libnames = ['libc.so.6', 'libc.so.0', 'libc.so']
for name in libnames:
try:
lib = ctypes.CDLL(name, mode=ctypes.RTLD_GLOBAL)
lib = ctypes.CDLL(name, mode=ctypes.RTLD_GLOBAL, use_errno=True)
return lib
except:
pass
Expand Down

0 comments on commit 342b2f1

Please sign in to comment.