Consolidate the libdir variable initialization code into xtables.c.
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
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);
int so_rev_target;
};
-extern char *lib_dir;
-
/* This is decleared in ip[6]tables.c */
extern struct afinfo afinfo;
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
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
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
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
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
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
#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;
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
*/
#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,
#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,