Hello,
On 05/29/2009 01:39 PM, Jan Janak wrote:
This is really confusing. Could you, please, describe how loadmodule works now?
it works same way was so far in SR (ser). In additions, you can have:
loadmodule "tm.so"
which is more or less equivalent to:
loadmodule "tm"
If ".so" is present, it will not be added.
The other addition, for K compatibility:
- if path in loadmodule is not absolute, has '/' inside , but does not start with '/', then will search it in loadpath, for example:
loadpath "/usr/local/ser/lib"
loadmodule "modules_k/pv.so"
In SER, was trying to load only "modules_k/pv.so"
Now, if "modules_k/pv.so" is not found, will try to see if "/usr/local/ser/lib/modules_k/pv.so" exists, and if yes, loads it.
Cheers, Daniel
Jan.
On 29-05 12:24, Daniel-Constantin Mierla wrote:
Module: sip-router Branch: master Commit: b27dfba5097af7e497c0177dd57f476f0b089ab4 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b27dfba5...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri May 29 13:08:05 2009 +0300
core: load_module - compatibility with K mod paths
preservation of SER and Kamailio module loading styles
loadmodule accepts "modname.so"
loadpath "searchpath" loadmodule "modpath"
- when modpath is modname or modname.so, search module at:
- searchpath/modname.so
- searchpath/modname/modname.so
- if modpath does not start with '/', search module at:
- modpath
- searchpath/modpath
sr_module.c | 111 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 77 insertions(+), 34 deletions(-)
diff --git a/sr_module.c b/sr_module.c index 7986720..e1da688 100644 --- a/sr_module.c +++ b/sr_module.c @@ -260,7 +260,7 @@ int load_module(char* mod_path) unsigned* mod_if_ver; struct sr_module* t; struct stat stat_buf;
- char* modname;
- str modname; char* mdir; char* nxt_mdir; char* path;
@@ -269,71 +269,114 @@ int load_module(char* mod_path) int dlflags; int new_dlflags; int retries;
- int path_type;
#ifndef RTLD_NOW /* for openbsd */ #define RTLD_NOW DL_LAZY #endif path=mod_path;
- if (!strchr(path, '/') && !strchr(path, '.')) {
- path_type = 0;
- modname.s = path;
- modname.len = strlen(mod_path);
- if(modname.len>3 && strcmp(modname.s+modname.len-3, ".so")==0) {
path_type = 1;
modname.len -= 3;
- }
- if (!strchr(path, '/'))
path_type |= 2;
- if((path_type&2) || path[0] != '/') { /* module name was given, we try to construct the path */
mdir=mods_dir; /* search path */ do{ nxt_mdir=strchr(mdir, ':'); if (nxt_mdir) mdir_len=(int)(nxt_mdir-mdir); else mdir_len=strlen(mdir);modname = path;
/* try path <MODS_DIR>/<modname>.so */
path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
strlen(modname) + 3 /* ".so" */ + 1);
if (path==0) goto error;
memcpy(path, mdir, mdir_len);
len = mdir_len;
if (len != 0 && path[len - 1] != '/'){
path[len]='/';
len++;
}
path[len]=0;
strcat(path, modname);
strcat(path, ".so");
if (stat(path, &stat_buf) == -1) {
DBG("load_module: module file not found <%s>\n", path);
pkg_free(path);
/* try path <MODS_DIR>/<modname>/<modname>.so */
path = (char*)pkg_malloc(
mdir_len + 1 /* "/" */ +
strlen(modname) + 1 /* "/" */ +
strlen(modname) + 3 /* ".so" */ + 1);
if(path_type&2) {
/* try path <MODS_DIR>/<modname>.so */
path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
modname.len + 3 /* ".so" */ + 1); if (path==0) goto error; memcpy(path, mdir, mdir_len); len = mdir_len;
if (len != 0 && path[len - 1] != '/') {
if (len != 0 && path[len - 1] != '/'){ path[len]='/'; len++; } path[len]=0;
strcat(path, modname);
strcat(path, "/");
strcat(path, modname);
strcat(path, ".so");
strcat(path, modname.s);
if(!(path_type&1))
strcat(path, ".so"); if (stat(path, &stat_buf) == -1) { DBG("load_module: module file not found <%s>\n", path); pkg_free(path);
path=0;
/* try path <MODS_DIR>/<modname>/<modname>.so */
path = (char*)pkg_malloc(
mdir_len + 1 /* "/" */ +
modname.len + 1 /* "/" */ +
modname.len + 3 /* ".so" */ + 1);
if (path==0) goto error;
memcpy(path, mdir, mdir_len);
len = mdir_len;
if (len != 0 && path[len - 1] != '/') {
path[len]='/';
len++;
}
path[len]=0;
strncat(path, modname.s, modname.len);
strcat(path, "/");
strcat(path, modname.s);
if(!(path_type&1))
strcat(path, ".so");
if (stat(path, &stat_buf) == -1) {
DBG("load_module: module file not found <%s>\n", path);
pkg_free(path);
path=0;
}
}
} else {
/* try mod_path - S compat */
if(path==mod_path) {
if (stat(path, &stat_buf) == -1) {
DBG("load_module: module file not found <%s>\n", path);
path=0;
}
}
if(path==0) {
/* try path <MODS_DIR>/mod_path - K compat */
path = (char*)pkg_malloc(mdir_len + 1 /* "/" */ +
strlen(mod_path) + 1);
if (path==0) goto error;
memcpy(path, mdir, mdir_len);
len = mdir_len;
if (len != 0 && path[len - 1] != '/'){
path[len]='/';
len++;
}
path[len]=0;
strcat(path, mod_path);
if (stat(path, &stat_buf) == -1) {
DBG("load_module: module file not found <%s>\n", path);
pkg_free(path);
path=0;
}while(path==0 && mdir); if (path==0){} } } mdir=nxt_mdir?nxt_mdir+1:0;
LOG(L_ERR, "ERROR: load_module: could not find module <%s> in"
" <%s>\n", modname, mods_dir);
LOG(L_ERR, "ERROR: load_module: could not find module <%.*s> in"
} }" <%s>\n", modname.len, modname.s, mods_dir); goto error;
- DBG("load_module: trying to load <%s>\n", path);
- retries=2; dlflags=RTLD_NOW;
reload:
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev