Explorar o código

core: shm mem size can now be set in the config script

shm mem size can now be set in the cfg script using
shm=size_in_mb,  shm_mem=size_in_mb or shm_mem_size=size_in_mb.
It must be set prior to any modparam or route block.
Specifying the memory size on the command line (-m size_in_mb)
will override the size from the config file.
(cherry picked from commit 647cc9832560590adc6e20685c2d53350a932fb2)
Andrei Pelinescu-Onciul %!s(int64=15) %!d(string=hai) anos
pai
achega
ecc3fd3f05
Modificáronse 3 ficheiros con 16 adicións e 2 borrados
  1. 4 0
      cfg.lex
  2. 11 1
      cfg.y
  3. 1 1
      main.c

+ 4 - 0
cfg.lex

@@ -80,6 +80,7 @@
  *  2009-03-10  added SET_USERPHONE action (Miklos)
  *  2009-04-24  add strlen, strempty and defined operators (andrei)
  *  2009-03-07  RETCODE, it's now  a core pvar (andrei)
+ *  2010-01-10  added SHM_MEM_SZ (andrei)
 */
 
 
@@ -444,6 +445,7 @@ ADVERTISED_ADDRESS	"advertised_address"
 ADVERTISED_PORT		"advertised_port"
 DISABLE_CORE		"disable_core_dump"
 OPEN_FD_LIMIT		"open_files_limit"
+SHM_MEM_SZ		"shm"|"shm_mem"|"shm_mem_size"
 SHM_FORCE_ALLOC		"shm_force_alloc"
 MLOCK_PAGES			"mlock_pages"
 REAL_TIME			"real_time"
@@ -839,6 +841,8 @@ EAT_ABLE	[\ \t\b\r]
 									return DISABLE_CORE; }
 <INITIAL>{OPEN_FD_LIMIT}		{	count(); yylval.strval=yytext;
 									return OPEN_FD_LIMIT; }
+<INITIAL>{SHM_MEM_SZ}		{	count(); yylval.strval=yytext;
+									return SHM_MEM_SZ; }
 <INITIAL>{SHM_FORCE_ALLOC}		{	count(); yylval.strval=yytext;
 									return SHM_FORCE_ALLOC; }
 <INITIAL>{MLOCK_PAGES}		{	count(); yylval.strval=yytext;

+ 11 - 1
cfg.y

@@ -96,7 +96,8 @@
  * 2009-01-26  case/switch() support (andrei)
  * 2009-03-10  added SET_USERPHONE action (Miklos)
  * 2009-05-04  switched if to rval_expr (andrei)
- * 2010-01-10  init shm on first mod_param or route block (andrei)
+ * 2010-01-10  init shm on first mod_param or route block;
+ *             added SHM_MEM_SZ (andrei)
 */
 
 %{
@@ -494,6 +495,7 @@ extern char *finame;
 %token ADVERTISED_PORT
 %token DISABLE_CORE
 %token OPEN_FD_LIMIT
+%token SHM_MEM_SZ
 %token SHM_FORCE_ALLOC
 %token MLOCK_PAGES
 %token REAL_TIME
@@ -1463,6 +1465,14 @@ assign_stm:
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
+	| SHM_MEM_SZ EQUAL NUMBER {
+		if (shm_initialized())
+			yyerror("shm/shm_mem_size must be before any modparam or the"
+					" route blocks");
+		else if (shm_mem_size == 0)
+			shm_mem_size=$3 * 1024 * 1024;
+	}
+	| SHM_MEM_SZ EQUAL error { yyerror("number expected"); }
 	| SHM_FORCE_ALLOC EQUAL NUMBER {
 		if (shm_initialized())
 			yyerror("shm_force_alloc must be before any modparam or the"

+ 1 - 1
main.c

@@ -469,7 +469,7 @@ int cfg_warnings=0;
 
 
 /* shared memory (in MB) */
-unsigned long shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
+unsigned long shm_mem_size=0;
 
 /* export command-line to anywhere else */
 int my_argc;