- when only module.so is given to loadmodule and mpath is set, try mpath/module/module.so if mpath/module.so is not found - useful when runing from sources tree - small adaptions because of renames in kamailio --- cfg.y | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-) diff --git a/cfg.y b/cfg.y index 44074ab..22a7b74 100644 --- a/cfg.y +++ b/cfg.y @@ -104,6 +104,8 @@ #include #include #include +#include +#include #include #include #include @@ -226,6 +228,7 @@ static int case_check_default(struct case_stms* stms); static char *mpath=NULL; static char mpath_buf[256]; static int mpath_len = 0; +static struct stat statf; %} @@ -1385,11 +1388,31 @@ cfg_var: } | ID DOT ID EQUAL error { yyerror("number or string expected"); } ; -module_stm: - LOADMODULE STRING { - if(*$2!='/' && mpath!=NULL && strlen($2)+mpath_len<255) - { +module_stm: LOADMODULE STRING { + if(*$2!='/' && mpath!=NULL && strlen($2)+mpath_len<255) { strcpy(mpath_buf+mpath_len, $2); + if (stat(mpath_buf, &statf) == -1) { + i_tmp = strlen(mpath_buf); + if(strchr($2, '/')==NULL && + strncmp(mpath_buf+i_tmp-3, ".so", 3)==0) + { + if(i_tmp+strlen($2)<255) + { + strcpy(mpath_buf+i_tmp-3, "/"); + strcpy(mpath_buf+i_tmp-2, $2); + if (stat(mpath_buf, &statf) == -1) { + mpath_buf[mpath_len]='\0'; + LOG(L_ERR, "module '%s' not found in '%s'\n", + $2, mpath_buf); + yyerror("failed to load module"); + } + } else { + yyerror("failed to load module - path too long"); + } + } else { + yyerror("failed to load module - not found"); + } + } DBG("loading module %s\n", mpath_buf); if (load_module(mpath_buf)!=0){ yyerror("failed to load module"); -- 1.5.6.5