Module: kamailio Branch: master Commit: 7fb667f309ef7f745fdeeaae46088648b004478c URL: https://github.com/kamailio/kamailio/commit/7fb667f309ef7f745fdeeaae46088648...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-07-26T10:20:10+02:00
core: support for modparam int stored in shared memory
- flag PARAM_USE_SHM has to be set
---
Modified: src/core/modparam.c Modified: src/core/sr_module.h
---
Diff: https://github.com/kamailio/kamailio/commit/7fb667f309ef7f745fdeeaae46088648... Patch: https://github.com/kamailio/kamailio/commit/7fb667f309ef7f745fdeeaae46088648...
---
diff --git a/src/core/modparam.c b/src/core/modparam.c index e3d8c1795e1..a486b041558 100644 --- a/src/core/modparam.c +++ b/src/core/modparam.c @@ -35,6 +35,7 @@ #include "pvar.h" #include "str_list.h" #include "mem/mem.h" +#include "mem/shm.h" #include <sys/types.h> #include <regex.h> #include <string.h> @@ -54,6 +55,13 @@ static char *get_mod_param_type_str(int ptype) return "func-unknown"; } } + if(ptype & PARAM_USE_SHM) { + if(ptype & PARAM_INT) { + return "shm-int"; + } else { + return "shm-unknown"; + } + } if(ptype & PARAM_STRING) { return "string"; } else if(ptype & PARAM_INT) { @@ -144,6 +152,25 @@ int set_mod_param_regex(char *regex, char *name, modparam_t type, void *val) pkg_free(reg); return -4; } + } else if(param_type & PARAM_USE_SHM) { + if(!shm_initialized()) { + LM_ERR("shared memory initialized\n"); + regfree(&preg); + pkg_free(reg); + return -1; + } + switch(PARAM_TYPE_MASK(param_type)) { + case PARAM_INT: + *((int **)ptr) = shm_malloc(sizeof(int)); + if(!*((int **)ptr)) { + SHM_MEM_ERROR; + regfree(&preg); + pkg_free(reg); + return -1; + } + *(*((int **)ptr)) = (int)(long)val2; + break; + } } else { switch(PARAM_TYPE_MASK(param_type)) { case PARAM_STRING: diff --git a/src/core/sr_module.h b/src/core/sr_module.h index 4dd92e996c7..d640e0022b6 100644 --- a/src/core/sr_module.h +++ b/src/core/sr_module.h @@ -111,9 +111,10 @@ typedef int (*child_init_function)(int rank); #define PARAM_STRING (1U << 0) /**< String (char *) parameter type */ #define PARAM_INT (1U << 1) /**< Integer parameter type */ #define PARAM_STR (1U << 2) /**< struct str parameter type */ -#define PARAM_VAR (1U << 3) /**< var parameter type - mdoparamx */ +#define PARAM_VAR (1U << 8) /**< var parameter type - mdoparamx */ +#define PARAM_USE_SHM (1U << (8 * sizeof(int) - 2)) #define PARAM_USE_FUNC (1U << (8 * sizeof(int) - 1)) -#define PARAM_TYPE_MASK(_x) ((_x) & (~PARAM_USE_FUNC)) +#define PARAM_TYPE_MASK(_x) ((_x) & (~(PARAM_USE_FUNC | PARAM_USE_SHM)))
typedef unsigned int modparam_t;