This is really confusing. Could you, please, describe how loadmodule works
now?
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=b27dfba…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)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 */
- modname = 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);
- /* 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;
+ }
}
}
mdir=nxt_mdir?nxt_mdir+1:0;
}while(path==0 && mdir);
if (path==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(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev