#! /bin/sh /usr/share/dpatch/dpatch-run ## module_path.dpatch by Tzafrir Cohen ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Allow loading modules from specific sub-directory (defined in the ## DP: config key "optim_dir" in the section "modules" in modules.conf) ## DP: ## DP: If such a key exists and a module exists in that subdirectory, ## DP: it will be loaded from there. @DPATCH@ diff -urNad asterisk-1.1.9.0beta1.dfsg.1/loader.c /tmp/dpep.bF5i9A/asterisk-1.1.9.0beta1.dfsg.1/loader.c --- asterisk-1.1.9.0beta1.dfsg.1/loader.c 2005-08-05 19:29:30.000000000 +0300 +++ /tmp/dpep.bF5i9A/asterisk-1.1.9.0beta1.dfsg.1/loader.c 2005-10-27 01:23:46.288669233 +0200 @@ -307,7 +307,21 @@ if (resource_name[0] == '/') { strncpy(fn, resource_name, sizeof(fn)-1); } else { - snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_MODULE_DIR, resource_name); + char *optim_dir = ast_variable_retrieve(cfg, "modules", "optim_dir"); + int has_fn = 0; + if (optim_dir != NULL){ + char fn_optim[256];// FIXME: make 256 a defined constant + snprintf(fn_optim, sizeof(fn), "%s/%s/%s", (char *)ast_config_AST_MODULE_DIR, optim_dir, resource_name); + if (access(fn_optim, R_OK)){ + ast_copy_string(fn, fn_optim, sizeof(fn)); + has_fn = 1; + if (option_debug) + ast_log(LOG_DEBUG, "Loading module from subdirectory %s: %s\n", optim_dir, fn); + } + } + if (! has_fn) { + snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_MODULE_DIR, resource_name); + } } m->lib = dlopen(fn, flags); if (!m->lib) {