Skip to content

Commit b88763c

Browse files
author
ldx
committed
Retrieve errno directly from libc.
Don't rely on ctypes.get_errno(), as it always seems to return 0. Use errno directly from libc.
1 parent b3e7774 commit b88763c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

iptc/ip4tc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
_IFNAMSIZ = 16
1818

19+
_libc = ct.CDLL("libc.so.6")
20+
_get_errno_loc = _libc.__errno_location
21+
_get_errno_loc.restype = ct.POINTER(ct.c_int)
22+
1923

2024
def is_table_available(name):
2125
try:
@@ -1371,8 +1375,7 @@ def builtin_chain(self, chain):
13711375

13721376
def strerror(self):
13731377
"""Returns any pending iptables error from the previous operation."""
1374-
errno = ct.get_errno()
1375-
ct.set_errno(0)
1378+
errno = _get_errno_loc()[0]
13761379
if errno == 0:
13771380
return "libiptc version error"
13781381
return self._iptc.iptc_strerror(errno)

0 commit comments

Comments
 (0)