Browse code

core: name of structure exported by a module can be prefixed with module name

- some modules use the flag for global exporting, which can lead to
naming conflicts
- related to GH#333

Daniel-Constantin Mierla authored on 20/09/2015 22:16:27
Showing 1 changed files
... ...
@@ -459,6 +459,8 @@ int load_module(char* mod_path)
459 459
 	int new_dlflags;
460 460
 	int retries;
461 461
 	int path_type;
462
+	str expref;
463
+	char exbuf[64];
462 464
 
463 465
 #ifndef RTLD_NOW
464 466
 /* for openbsd */
... ...
@@ -611,9 +613,24 @@ reload:
611 611
 		}
612 612
 	}
613 613
 	exp = (union module_exports_u*)dlsym(handle, DLSYM_PREFIX "exports");
614
-	if ( (error =(char*)dlerror())!=0 ){
615
-		LM_ERR("%s\n", error);
616
-		goto error1;
614
+	if(exp==NULL) {
615
+		/* 'exports' structure not found, look up for '_modulename_exports' */
616
+		mdir = strrchr(mod_path, '/');
617
+		if (!mdir) {
618
+			expref.s = mod_path;
619
+		} else {
620
+			expref.s = mdir+1;
621
+		}
622
+		expref.len = strlen(expref.s);
623
+		if(expref.len>3 && strcmp(expref.s+expref.len-3, ".so")==0)
624
+			expref.len -= 3;
625
+		snprintf(exbuf, 62, DLSYM_PREFIX "_%.*s_exports", expref.len, expref.s);
626
+		exp = (union module_exports_u*)dlsym(handle, exbuf);
627
+		LM_DBG("looking up exports with name: %s\n", exbuf);
628
+		if ( (error =(char*)dlerror())!=0 ){
629
+			LM_ERR("%s\n", error);
630
+			goto error1;
631
+		}
617 632
 	}
618 633
 	/* hack to allow for kamailio style dlflags inside exports */
619 634
 	if (*mod_if_ver == 1) {