Browse code

core: early shm init while parsing the cfg

- shm memory is now initialized before the first modparam or the
first route block. This allows using shm memory early, in
modparam fixups or route block parsing functions.
user and shm_force_alloc must be used _before_ any modparam or
route block (using them after a modparam or a route block will
now generate an error).
- the user in the cfg is ignored if already set from the command
line

Andrei Pelinescu-Onciul authored on 10/01/2010 11:54:05
Showing 1 changed files
... ...
@@ -96,6 +96,7 @@
96 96
  * 2009-01-26  case/switch() support (andrei)
97 97
  * 2009-03-10  added SET_USERPHONE action (Miklos)
98 98
  * 2009-05-04  switched if to rval_expr (andrei)
99
+ * 2010-01-10  init shm on first mod_param or route block (andrei)
99 100
 */
100 101
 
101 102
 %{
... ...
@@ -111,6 +112,9 @@
111 111
 #include <errno.h>
112 112
 #include "route_struct.h"
113 113
 #include "globals.h"
114
+#ifdef SHM_MEM
115
+#include "shm_init.h"
116
+#endif /* SHM_MEM */
114 117
 #include "route.h"
115 118
 #include "switch.h"
116 119
 #include "dprint.h"
... ...
@@ -867,8 +871,20 @@ assign_stm:
867 867
 	| MEMSUM EQUAL error { yyerror("int value expected"); }
868 868
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
869 869
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
870
-	| USER EQUAL STRING     { user=$3; }
871
-	| USER EQUAL ID         { user=$3; }
870
+	| USER EQUAL STRING     {
871
+		if (shm_initialized())
872
+			yyerror("user must be before any modparam or the"
873
+					" route blocks");
874
+		else if (user==0)
875
+			user=$3; 
876
+	}
877
+	| USER EQUAL ID         {
878
+		if (shm_initialized())
879
+			yyerror("user must be before any modparam or the"
880
+					" route blocks");
881
+		else if (user==0)
882
+			user=$3;
883
+	}
872 884
 	| USER EQUAL error      { yyerror("string value expected"); }
873 885
 	| GROUP EQUAL STRING     { group=$3; }
874 886
 	| GROUP EQUAL ID         { group=$3; }
... ...
@@ -1447,7 +1463,13 @@ assign_stm:
1447 1447
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1448 1448
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1449 1449
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1450
-	| SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
1450
+	| SHM_FORCE_ALLOC EQUAL NUMBER {
1451
+		if (shm_initialized())
1452
+			yyerror("shm_force_alloc must be before any modparam or the"
1453
+					" route blocks");
1454
+		else
1455
+			shm_force_alloc=$3;
1456
+	}
1451 1457
 	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1452 1458
 	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1453 1459
 	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
... ...
@@ -1560,11 +1582,23 @@ module_stm:
1560 1560
 	}
1561 1561
 	| LOADPATH EQUAL error	{ yyerror("string expected"); }
1562 1562
 	| MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1563
+	#ifdef SHM_MEM
1564
+		if (!shm_initialized() && init_shm()<0) {
1565
+			yyerror("Can't initialize shared memory");
1566
+			YYABORT;
1567
+		}
1568
+	#endif /* SHM_MEM */
1563 1569
 		if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1564 1570
 			 yyerror("Can't set module parameter");
1565 1571
 		}
1566 1572
 	}
1567
-        | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1573
+	| MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1574
+	#ifdef SHM_MEM
1575
+		if (!shm_initialized() && init_shm()<0) {
1576
+			yyerror("Can't initialize shared memory");
1577
+			YYABORT;
1578
+		}
1579
+	#endif /* SHM_MEM */
1568 1580
 		if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1569 1581
 			 yyerror("Can't set module parameter");
1570 1582
 		}
... ...
@@ -1645,8 +1679,22 @@ route_name:		NUMBER	{
1645 1645
 ;
1646 1646
 
1647 1647
 route_stm:
1648
-	ROUTE LBRACE actions RBRACE { push($3, &main_rt.rlist[DEFAULT_RT]); }
1648
+	ROUTE LBRACE actions RBRACE {
1649
+	#ifdef SHM_MEM
1650
+		if (!shm_initialized() && init_shm()<0) {
1651
+			yyerror("Can't initialize shared memory");
1652
+			YYABORT;
1653
+		}
1654
+	#endif /* SHM_MEM */
1655
+		push($3, &main_rt.rlist[DEFAULT_RT]);
1656
+	}
1649 1657
 	| ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
1658
+	#ifdef SHM_MEM
1659
+		if (!shm_initialized() && init_shm()<0) {
1660
+			yyerror("Can't initialize shared memory");
1661
+			YYABORT;
1662
+		}
1663
+	#endif /* SHM_MEM */
1650 1664
 		i_tmp=route_get(&main_rt, $3);
1651 1665
 		if (i_tmp==-1){
1652 1666
 			yyerror("internal error");
... ...
@@ -1662,9 +1710,21 @@ route_stm:
1662 1662
 	;
1663 1663
 failure_route_stm:
1664 1664
 	ROUTE_FAILURE LBRACE actions RBRACE {
1665
-									push($3, &failure_rt.rlist[DEFAULT_RT]);
1666
-										}
1665
+	#ifdef SHM_MEM
1666
+		if (!shm_initialized() && init_shm()<0) {
1667
+			yyerror("Can't initialize shared memory");
1668
+			YYABORT;
1669
+		}
1670
+	#endif /* SHM_MEM */
1671
+		push($3, &failure_rt.rlist[DEFAULT_RT]);
1672
+	}
1667 1673
 	| ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1674
+	#ifdef SHM_MEM
1675
+		if (!shm_initialized() && init_shm()<0) {
1676
+			yyerror("Can't initialize shared memory");
1677
+			YYABORT;
1678
+		}
1679
+	#endif /* SHM_MEM */
1668 1680
 		i_tmp=route_get(&failure_rt, $3);
1669 1681
 		if (i_tmp==-1){
1670 1682
 			yyerror("internal error");
... ...
@@ -1680,9 +1740,21 @@ failure_route_stm:
1680 1680
 	;
1681 1681
 onreply_route_stm:
1682 1682
 	ROUTE_ONREPLY LBRACE actions RBRACE {
1683
-									push($3, &onreply_rt.rlist[DEFAULT_RT]);
1684
-										}
1683
+	#ifdef SHM_MEM
1684
+		if (!shm_initialized() && init_shm()<0) {
1685
+			yyerror("Can't initialize shared memory");
1686
+			YYABORT;
1687
+		}
1688
+	#endif /* SHM_MEM */
1689
+		push($3, &onreply_rt.rlist[DEFAULT_RT]);
1690
+	}
1685 1691
 	| ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
1692
+	#ifdef SHM_MEM
1693
+		if (!shm_initialized() && init_shm()<0) {
1694
+			yyerror("Can't initialize shared memory");
1695
+			YYABORT;
1696
+		}
1697
+	#endif /* SHM_MEM */
1686 1698
 		i_tmp=route_get(&onreply_rt, $3);
1687 1699
 		if (i_tmp==-1){
1688 1700
 			yyerror("internal error");
... ...
@@ -1698,9 +1770,21 @@ onreply_route_stm:
1698 1698
 	;
1699 1699
 branch_route_stm:
1700 1700
 	ROUTE_BRANCH LBRACE actions RBRACE {
1701
-									push($3, &branch_rt.rlist[DEFAULT_RT]);
1702
-										}
1701
+	#ifdef SHM_MEM
1702
+		if (!shm_initialized() && init_shm()<0) {
1703
+			yyerror("Can't initialize shared memory");
1704
+			YYABORT;
1705
+		}
1706
+	#endif /* SHM_MEM */
1707
+		push($3, &branch_rt.rlist[DEFAULT_RT]);
1708
+	}
1703 1709
 	| ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1710
+	#ifdef SHM_MEM
1711
+		if (!shm_initialized() && init_shm()<0) {
1712
+			yyerror("Can't initialize shared memory");
1713
+			YYABORT;
1714
+		}
1715
+	#endif /* SHM_MEM */
1704 1716
 		i_tmp=route_get(&branch_rt, $3);
1705 1717
 		if (i_tmp==-1){
1706 1718
 			yyerror("internal error");
... ...
@@ -1715,9 +1799,21 @@ branch_route_stm:
1715 1715
 	| ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1716 1716
 	;
1717 1717
 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1718
-									push($3, &onsend_rt.rlist[DEFAULT_RT]);
1719
-												}
1718
+	#ifdef SHM_MEM
1719
+		if (!shm_initialized() && init_shm()<0) {
1720
+			yyerror("Can't initialize shared memory");
1721
+			YYABORT;
1722
+		}
1723
+	#endif /* SHM_MEM */
1724
+		push($3, &onsend_rt.rlist[DEFAULT_RT]);
1725
+	}
1720 1726
 	| ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1727
+	#ifdef SHM_MEM
1728
+		if (!shm_initialized() && init_shm()<0) {
1729
+			yyerror("Can't initialize shared memory");
1730
+			YYABORT;
1731
+		}
1732
+	#endif /* SHM_MEM */
1721 1733
 		i_tmp=route_get(&onsend_rt, $3);
1722 1734
 		if (i_tmp==-1){
1723 1735
 			yyerror("internal error");
... ...
@@ -1732,6 +1828,12 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1732 1732
 	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1733 1733
 	;
1734 1734
 event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1735
+	#ifdef SHM_MEM
1736
+		if (!shm_initialized() && init_shm()<0) {
1737
+			yyerror("Can't initialize shared memory");
1738
+			YYABORT;
1739
+		}
1740
+	#endif /* SHM_MEM */
1735 1741
 		i_tmp=route_get(&event_rt, $3);
1736 1742
 		if (i_tmp==-1){
1737 1743
 			yyerror("internal error");