2
0
Эх сурвалжийг харах

core: added option 'o' for loadmodule

- do not error and exit when a module is already loaded
- GH #4126
Daniel-Constantin Mierla 7 сар өмнө
parent
commit
914b154a90

+ 11 - 0
src/core/sr_module.c

@@ -567,6 +567,7 @@ int ksr_load_module(char *mod_path, char *opts)
 	module_exports_t *exp;
 	module_exports_t *exp;
 	struct sr_module *t;
 	struct sr_module *t;
 	int dlflags;
 	int dlflags;
+	int ldopt;
 	int new_dlflags;
 	int new_dlflags;
 	int retries;
 	int retries;
 	char *path = NULL;
 	char *path = NULL;
@@ -592,11 +593,14 @@ int ksr_load_module(char *mod_path, char *opts)
 
 
 	retries = 2;
 	retries = 2;
 	dlflags = RTLD_NOW;
 	dlflags = RTLD_NOW;
+	ldopt = 0;
 
 
 	if(opts != NULL) {
 	if(opts != NULL) {
 		for(p = opts; *p != '\0'; p++) {
 		for(p = opts; *p != '\0'; p++) {
 			if(*p == 'G' || *p == 'g') {
 			if(*p == 'G' || *p == 'g') {
 				dlflags |= RTLD_GLOBAL;
 				dlflags |= RTLD_GLOBAL;
+			} else if(*p == 'O' || *p == 'o') {
+				ldopt = 1;
 			} else {
 			} else {
 				LM_INFO("unknown option: %c\n", *p);
 				LM_INFO("unknown option: %c\n", *p);
 			}
 			}
@@ -612,6 +616,13 @@ reload:
 
 
 	for(t = modules; t; t = t->next) {
 	for(t = modules; t; t = t->next) {
 		if(t->handle == handle) {
 		if(t->handle == handle) {
+			if(ldopt == 1) {
+				if(path && path != mod_path) {
+					pkg_free(path);
+				}
+				LM_DBG("skip loading optional module twice (%s)\n", path);
+				return 0;
+			}
 			LM_WARN("attempting to load the same module twice (%s)\n", path);
 			LM_WARN("attempting to load the same module twice (%s)\n", path);
 			goto skip;
 			goto skip;
 		}
 		}