Browse Source

core: support for modparam int stored in shared memory

- flag PARAM_USE_SHM has to be set
Daniel-Constantin Mierla 1 tháng trước cách đây
mục cha
commit
7fb667f309
2 tập tin đã thay đổi với 30 bổ sung2 xóa
  1. 27 0
      src/core/modparam.c
  2. 3 2
      src/core/sr_module.h

+ 27 - 0
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:

+ 3 - 2
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;