Module: kamailio Branch: master Commit: 914b154a9096f2c17a4aa362f54358e10c2cce76 URL: https://github.com/kamailio/kamailio/commit/914b154a9096f2c17a4aa362f54358e1...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-02-18T15:49:51+01:00
core: added option 'o' for loadmodule
- do not error and exit when a module is already loaded - GH #4126
---
Modified: src/core/sr_module.c
---
Diff: https://github.com/kamailio/kamailio/commit/914b154a9096f2c17a4aa362f54358e1... Patch: https://github.com/kamailio/kamailio/commit/914b154a9096f2c17a4aa362f54358e1...
---
diff --git a/src/core/sr_module.c b/src/core/sr_module.c index f19a2d3812b..a2e28acf030 100644 --- a/src/core/sr_module.c +++ b/src/core/sr_module.c @@ -567,6 +567,7 @@ int ksr_load_module(char *mod_path, char *opts) module_exports_t *exp; struct sr_module *t; int dlflags; + int ldopt; int new_dlflags; int retries; char *path = NULL; @@ -592,11 +593,14 @@ int ksr_load_module(char *mod_path, char *opts)
retries = 2; dlflags = RTLD_NOW; + ldopt = 0;
if(opts != NULL) { for(p = opts; *p != '\0'; p++) { if(*p == 'G' || *p == 'g') { dlflags |= RTLD_GLOBAL; + } else if(*p == 'O' || *p == 'o') { + ldopt = 1; } else { LM_INFO("unknown option: %c\n", *p); } @@ -612,6 +616,13 @@ int ksr_load_module(char *mod_path, char *opts)
for(t = modules; t; t = t->next) { 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); goto skip; }