Skip to content

Commit e167818

Browse files
author
ldx
committed
Try to detect xtables extension directory.
If extensions are installed in a non-standard location, it can be set via the environment variable XTABLES_LIBDIR.
1 parent e82d6d2 commit e167818

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

iptc/xtables.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import ctypes as ct
4+
import os
45
import sys
56
import weakref
67
import version
@@ -689,6 +690,17 @@ class XTablesError(Exception):
689690
_optarg = ct.c_char_p.in_dll(_libc, "optarg")
690691

691692
_lib_xtables, _xtables_version = find_library("xtables")
693+
_xtables_libdir = os.getenv("XTABLES_LIBDIR")
694+
if _xtables_libdir is None:
695+
import os.path
696+
for xtdir in ["/lib/xtables", "/usr/lib/xtables",
697+
"/usr/local/lib/xtables"]:
698+
if os.path.isdir(xtdir):
699+
_xtables_libdir = xtdir
700+
break
701+
if _xtables_libdir is None:
702+
raise XTablesError("can't find directory with extensions; "
703+
"please set XTABLES_LIBDIR")
692704

693705
_lib_xtwrapper, _ = find_library("xtwrapper")
694706

@@ -878,8 +890,8 @@ def _try_register(self, name):
878890
return
879891
afinfo = ct.cast(self._afinfo, ct.POINTER(xtables_afinfo))
880892
prefix = afinfo[0].libprefix
881-
libs = ["/lib/xtables/libxt_" + name + ".so",
882-
"/lib/xtables/" + prefix + name + ".so"]
893+
libs = [os.path.join(_xtables_libdir, "libxt_" + name + ".so"),
894+
os.path.join(_xtables_libdir, prefix + name + ".so")]
883895
for lib in libs:
884896
if self._try_extinit(name, lib):
885897
return

0 commit comments

Comments
 (0)