MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / sr_load_module

Function sr_load_module

sr_module.c:263–326  ·  view source on GitHub ↗

returns 0 on success , <0 on error */

Source from the content-addressed store, hash-verified

261
262/* returns 0 on success , <0 on error */
263int sr_load_module(char* path)
264{
265 void* handle;
266 unsigned int moddlflags;
267 char* error;
268 const struct module_exports* exp;
269 struct sr_module* t;
270
271 /* load module */
272 handle=dlopen(path, OPENSIPS_DLFLAGS); /* resolve all symbols now */
273 if (handle==0){
274 LM_ERR("could not open module <%s>: %s\n", path, dlerror() );
275 goto error;
276 }
277
278 /* check for duplicates */
279 for(t=modules;t; t=t->next){
280 if (t->handle==handle){
281 LM_WARN("attempting to load the same module twice (%s)\n", path);
282 goto skip;
283 }
284 }
285
286 /* import module interface */
287 exp = (const struct module_exports*)dlsym(handle, DLSYM_PREFIX "exports");
288 if ( (error =(char*)dlerror())!=0 ){
289 LM_ERR("load_module: %s\n", error);
290 goto error1;
291 }
292 /* version control */
293 if (!version_control(exp, path)) {
294 exit(1);
295 }
296 if(exp->dlflags!=DEFAULT_DLFLAGS && exp->dlflags!=OPENSIPS_DLFLAGS) {
297 moddlflags = exp->dlflags;
298 dlclose(handle);
299 LM_DBG("reloading module %s with flags %d\n", path, moddlflags);
300 handle = dlopen(path, moddlflags);
301 if (handle==0){
302 LM_ERR("could not open module <%s>: %s\n", path, dlerror() );
303 goto error;
304 }
305 exp = (const struct module_exports*)dlsym(handle, DLSYM_PREFIX "exports");
306 if ( (error =(char*)dlerror())!=0 ){
307 LM_ERR("failed to load module : %s\n", error);
308 goto error1;
309 }
310 }
311
312 if (exp->load_f && exp->load_f() < 0) {
313 LM_ERR("could not initialize module %s\n", path);
314 goto error1;
315 }
316
317 /* launch register */
318 if (register_module(exp, path, handle)<0) goto error1;
319 return 0;
320

Callers 1

load_moduleFunction · 0.85

Calls 2

version_controlFunction · 0.85
register_moduleFunction · 0.85

Tested by

no test coverage detected