Browse Source

core: make the pointer to the list of loaded modules static

Daniel-Constantin Mierla 1 month ago
parent
commit
783740267e
3 changed files with 18 additions and 16 deletions
  1. 3 1
      src/core/modparam.c
  2. 15 14
      src/core/sr_module.c
  3. 0 1
      src/core/sr_module.h

+ 3 - 1
src/core/modparam.c

@@ -79,6 +79,7 @@ int set_mod_param_regex(char *regex, char *name, modparam_t type, void *val)
 	void *ptr, *val2;
 	void *ptr, *val2;
 	modparam_t param_type;
 	modparam_t param_type;
 	str s;
 	str s;
+	sr_module_t *lmodules = NULL;
 
 
 	if(!regex) {
 	if(!regex) {
 		LM_ERR("Invalid mod parameter value\n");
 		LM_ERR("Invalid mod parameter value\n");
@@ -109,7 +110,8 @@ int set_mod_param_regex(char *regex, char *name, modparam_t type, void *val)
 	}
 	}
 
 
 	mod_found = 0;
 	mod_found = 0;
-	for(t = modules; t; t = t->next) {
+	lmodules = get_loaded_modules();
+	for(t = lmodules; t; t = t->next) {
 		if(regexec(&preg, t->exports.name, 0, 0, 0) == 0) {
 		if(regexec(&preg, t->exports.name, 0, 0, 0) == 0) {
 			LM_DBG("'%s' matches module '%s'\n", regex, t->exports.name);
 			LM_DBG("'%s' matches module '%s'\n", regex, t->exports.name);
 			mod_found = 1;
 			mod_found = 1;

+ 15 - 14
src/core/sr_module.c

@@ -59,7 +59,7 @@
 #include <stddef.h> /* for offsetof */
 #include <stddef.h> /* for offsetof */
 
 
 
 
-struct sr_module *modules = 0;
+static struct sr_module *_ksr_modules_list = NULL;
 static str_list_t *_ksr_loadmod_strlist = NULL;
 static str_list_t *_ksr_loadmod_strlist = NULL;
 
 
 
 
@@ -336,8 +336,8 @@ static int register_module(module_exports_t *e, char *path, void *handle)
 	}
 	}
 
 
 	/* link module in the list */
 	/* link module in the list */
-	mod->next = modules;
-	modules = mod;
+	mod->next = _ksr_modules_list;
+	_ksr_modules_list = mod;
 	return 0;
 	return 0;
 error:
 error:
 	if(mod)
 	if(mod)
@@ -614,7 +614,7 @@ reload:
 		goto error;
 		goto error;
 	}
 	}
 
 
-	for(t = modules; t; t = t->next) {
+	for(t = _ksr_modules_list; t; t = t->next) {
 		if(t->handle == handle) {
 		if(t->handle == handle) {
 			if(ldopt == 1) {
 			if(ldopt == 1) {
 				if(path) {
 				if(path) {
@@ -763,7 +763,7 @@ ksr_cmd_export_t *find_mod_export_record(
 	struct sr_module *t;
 	struct sr_module *t;
 	ksr_cmd_export_t *cmd;
 	ksr_cmd_export_t *cmd;
 
 
-	for(t = modules; t; t = t->next) {
+	for(t = _ksr_modules_list; t; t = t->next) {
 		if(mod != 0 && (strcmp(t->exports.name, mod) != 0))
 		if(mod != 0 && (strcmp(t->exports.name, mod) != 0))
 			continue;
 			continue;
 		if(t->exports.cmds)
 		if(t->exports.cmds)
@@ -832,7 +832,7 @@ struct sr_module *find_module_by_name(char *mod)
 {
 {
 	struct sr_module *t;
 	struct sr_module *t;
 
 
-	for(t = modules; t; t = t->next) {
+	for(t = _ksr_modules_list; t; t = t->next) {
 		if(strcmp(mod, t->exports.name) == 0) {
 		if(strcmp(mod, t->exports.name) == 0) {
 			return t;
 			return t;
 		}
 		}
@@ -843,7 +843,7 @@ struct sr_module *find_module_by_name(char *mod)
 
 
 sr_module_t *get_loaded_modules(void)
 sr_module_t *get_loaded_modules(void)
 {
 {
-	return modules;
+	return _ksr_modules_list;
 }
 }
 
 
 /*!
 /*!
@@ -888,7 +888,7 @@ void destroy_modules()
 	LM_DBG("starting modules destroy phase\n");
 	LM_DBG("starting modules destroy phase\n");
 
 
 	/* call first destroy function from each module */
 	/* call first destroy function from each module */
-	t = modules;
+	t = _ksr_modules_list;
 	while(t) {
 	while(t) {
 		foo = t->next;
 		foo = t->next;
 		if(t->exports.destroy_mod_f) {
 		if(t->exports.destroy_mod_f) {
@@ -897,13 +897,13 @@ void destroy_modules()
 		t = foo;
 		t = foo;
 	}
 	}
 	/* free module exports structures */
 	/* free module exports structures */
-	t = modules;
+	t = _ksr_modules_list;
 	while(t) {
 	while(t) {
 		foo = t->next;
 		foo = t->next;
 		pkg_free(t);
 		pkg_free(t);
 		t = foo;
 		t = foo;
 	}
 	}
-	modules = 0;
+	_ksr_modules_list = 0;
 	if(mod_response_cbks) {
 	if(mod_response_cbks) {
 		pkg_free(mod_response_cbks);
 		pkg_free(mod_response_cbks);
 		mod_response_cbks = 0;
 		mod_response_cbks = 0;
@@ -1010,7 +1010,7 @@ int init_child(int rank)
 		}
 		}
 	}
 	}
 
 
-	ret = init_mod_child(modules, rank);
+	ret = init_mod_child(_ksr_modules_list, rank);
 	if(rank != PROC_INIT && rank != PROC_POSTCHILDINIT) {
 	if(rank != PROC_INIT && rank != PROC_POSTCHILDINIT) {
 		pt[process_no].status = 1;
 		pt[process_no].status = 1;
 	}
 	}
@@ -1078,11 +1078,11 @@ int init_modules(void)
 	if(async_task_init() < 0)
 	if(async_task_init() < 0)
 		return -1;
 		return -1;
 
 
-	i = init_mod(modules);
+	i = init_mod(_ksr_modules_list);
 	if(i != 0)
 	if(i != 0)
 		return i;
 		return i;
 
 
-	for(t = modules; t; t = t->next)
+	for(t = _ksr_modules_list; t; t = t->next)
 		if(t->exports.response_f)
 		if(t->exports.response_f)
 			mod_response_cbk_no++;
 			mod_response_cbk_no++;
 	mod_response_cbks =
 	mod_response_cbks =
@@ -1091,7 +1091,8 @@ int init_modules(void)
 		PKG_MEM_ERROR;
 		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
-	for(t = modules, i = 0; t && (i < mod_response_cbk_no); t = t->next)
+	for(t = _ksr_modules_list, i = 0; t && (i < mod_response_cbk_no);
+			t = t->next)
 		if(t->exports.response_f) {
 		if(t->exports.response_f) {
 			mod_response_cbks[i] = t->exports.response_f;
 			mod_response_cbks[i] = t->exports.response_f;
 			i++;
 			i++;

+ 0 - 1
src/core/sr_module.h

@@ -345,7 +345,6 @@ typedef struct sr_module
 } sr_module_t;
 } sr_module_t;
 
 
 
 
-extern sr_module_t *modules;				 /**< global module list*/
 extern response_function *mod_response_cbks; /**< response callback array */
 extern response_function *mod_response_cbks; /**< response callback array */
 extern int mod_response_cbk_no; /**< size of response callbacks array */
 extern int mod_response_cbk_no; /**< size of response callbacks array */