]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: prefix/order - libdir
authorJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 14:59:06 +0000 (15:59 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Tue, 27 Jan 2009 22:14:30 +0000 (23:14 +0100)
Consolidate the libdir variable initialization code into xtables.c.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
include/xtables.h.in
include/xtables/internal.h
ip6tables-restore.c
ip6tables-save.c
ip6tables-standalone.c
iptables-restore.c
iptables-save.c
iptables-standalone.c
xtables.c

index 02a832db11e3b3f548d8576b487a802d74d9105a..268c42e438b22e8f87b264284b4aa3d086cf3d50 100644 (file)
@@ -159,6 +159,7 @@ extern const char *xtables_modprobe_program;
 extern struct xtables_match *xtables_matches;
 extern struct xtables_target *xtables_targets;
 
+extern void xtables_init(void);
 extern void *xtables_calloc(size_t, size_t);
 extern void *xtables_malloc(size_t);
 
index 60375cd1df7f211c9716ea3e0371bed2fd22d4d7..21c4401f2febbfd6ea1b935cbe5c8d3a49fa7fea 100644 (file)
@@ -26,8 +26,6 @@ struct afinfo {
        int so_rev_target;
 };
 
-extern char *lib_dir;
-
 /* This is decleared in ip[6]tables.c */
 extern struct afinfo afinfo;
 
index 097711f3557ae67550a53ae8498d374dea001d61..6be1a36c8ac7b6cd641f0137c36cf455ad56307f 100644 (file)
@@ -130,16 +130,7 @@ int main(int argc, char *argv[])
        program_version = XTABLES_VERSION;
        line = 0;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IP6TABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index 11ef8c48d75d75a77784e4706b193d79d797a617..1b9d00aec3f306fe3d2286362878e38d78d54915 100644 (file)
@@ -139,16 +139,7 @@ int main(int argc, char *argv[])
        program_name = "ip6tables-save";
        program_version = XTABLES_VERSION;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IP6TABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index f4b1f18f1e21e01ad7daf891aed583c228eaf88c..95435576c2dd4c9c5bfcd542cf87210b31ef7c76 100644 (file)
@@ -52,16 +52,7 @@ main(int argc, char *argv[])
        program_name = "ip6tables";
        program_version = XTABLES_VERSION;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IP6TABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index 3fbc90870f440422034a4143da0d747ff850cf2c..d982fca156b0db1b5ee88130d5070ea9c640bfdd 100644 (file)
@@ -132,16 +132,7 @@ main(int argc, char *argv[])
        program_version = XTABLES_VERSION;
        line = 0;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IPTABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IPTABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index 7118d1f2852aa79574573d396d4d300c707af9f5..e615de990d2b5773c7f36e37fe9e8fc5d179cccf 100644 (file)
@@ -139,16 +139,7 @@ main(int argc, char *argv[])
        program_name = "iptables-save";
        program_version = XTABLES_VERSION;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IPTABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IPTABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index 3f2432fe4a1eecdaa590a27340581b07f6393a33..c06b28623f02156ce7b92779cdd3f465ced7e054 100644 (file)
@@ -53,16 +53,7 @@ main(int argc, char *argv[])
        program_name = "iptables";
        program_version = XTABLES_VERSION;
 
-       lib_dir = getenv("XTABLES_LIBDIR");
-       if (lib_dir == NULL) {
-               lib_dir = getenv("IPTABLES_LIB_DIR");
-               if (lib_dir != NULL)
-                       fprintf(stderr, "IPTABLES_LIB_DIR is deprecated, "
-                               "use XTABLES_LIBDIR.\n");
-       }
-       if (lib_dir == NULL)
-               lib_dir = XTABLES_LIBDIR;
-
+       xtables_init();
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif
index fb5cc628d0564270d1250760ea50b00643dd5bcf..85bd76c00375394fb82b5d9e173a682fe97bfd19 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -44,7 +44,8 @@
 #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
 #endif
 
-char *lib_dir;
+/* Search path for Xtables .so files */
+static const char *xtables_libdir;
 
 /* the path to command to load kernel module */
 const char *xtables_modprobe_program;
@@ -53,6 +54,20 @@ const char *xtables_modprobe_program;
 struct xtables_match *xtables_matches;
 struct xtables_target *xtables_targets;
 
+void xtables_init(void)
+{
+       xtables_libdir = getenv("XTABLES_LIBDIR");
+       if (xtables_libdir != NULL)
+               return;
+       xtables_libdir = getenv("IPTABLES_LIB_DIR");
+       if (xtables_libdir != NULL) {
+               fprintf(stderr, "IPTABLES_LIB_DIR is deprecated, "
+                       "use XTABLES_LIBDIR.\n");
+               return;
+       }
+       xtables_libdir = XTABLES_LIBDIR;
+}
+
 /**
  * xtables_*alloc - wrappers that exit on failure
  */
@@ -398,7 +413,8 @@ xtables_find_match(const char *name, enum xtables_tryload tryload,
 
 #ifndef NO_SHARED_LIBS
        if (!ptr && tryload != XTF_DONT_LOAD && tryload != XTF_DURING_LOAD) {
-               ptr = load_extension(lib_dir, afinfo.libprefix, name, false);
+               ptr = load_extension(xtables_libdir, afinfo.libprefix,
+                     name, false);
 
                if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED)
                        exit_error(PARAMETER_PROBLEM,
@@ -457,7 +473,8 @@ xtables_find_target(const char *name, enum xtables_tryload tryload)
 
 #ifndef NO_SHARED_LIBS
        if (!ptr && tryload != XTF_DONT_LOAD && tryload != XTF_DURING_LOAD) {
-               ptr = load_extension(lib_dir, afinfo.libprefix, name, true);
+               ptr = load_extension(xtables_libdir, afinfo.libprefix,
+                     name, true);
 
                if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED)
                        exit_error(PARAMETER_PROBLEM,