#! /bin/sh /usr/share/dpatch/dpatch-run ## modules_extradir.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 "extradir" 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.2.0.dfsg/loader.c /tmp/dpep.eh2OtD/asterisk-1.2.0.dfsg/loader.c --- asterisk-1.2.0.dfsg/loader.c 2005-10-24 22:12:05.000000000 +0200 +++ /tmp/dpep.eh2OtD/asterisk-1.2.0.dfsg/loader.c 2005-12-05 23:59:48.178859884 +0200 @@ -270,6 +270,7 @@ static int __load_resource(const char *resource_name, const struct ast_config *cfg) { static char fn[256]; + char extradir[256] = ""; // TODO: use a defined constant int errors=0; int res; struct module *m; @@ -296,6 +297,12 @@ flags = RTLD_LAZY; #endif } + { + if (cfg) { + if (val = ast_variable_retrieve(cfg, "modules", "extradir")) + ast_copy_string(extradir, val, sizeof(extradir)); + } + } if (ast_mutex_lock(&modlock)) ast_log(LOG_WARNING, "Failed to lock\n"); @@ -318,7 +325,10 @@ 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); + snprintf(fn, sizeof(fn), "%s/%s/%s", (char *)ast_config_AST_MODULE_DIR, extradir, resource_name); + if (access(fn,R_OK) != 0) {// if not readable or not there: + snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_MODULE_DIR, resource_name); + } } m->lib = dlopen(fn, flags); if (!m->lib) {