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 112
 #include <errno.h>
112 113
 #include "route_struct.h"
113 114
 #include "globals.h"
115
+#ifdef SHM_MEM
116
+#include "shm_init.h"
117
+#endif /* SHM_MEM */
114 118
 #include "route.h"
115 119
 #include "switch.h"
116 120
 #include "dprint.h"
... ...
@@ -867,8 +871,20 @@ assign_stm:
867 871
 	| MEMSUM EQUAL error { yyerror("int value expected"); }
868 872
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
869 873
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
870
-	| USER EQUAL STRING     { user=$3; }
871
-	| USER EQUAL ID         { user=$3; }
874
+	| USER EQUAL STRING     {
875
+		if (shm_initialized())
876
+			yyerror("user must be before any modparam or the"
877
+					" route blocks");
878
+		else if (user==0)
879
+			user=$3; 
880
+	}
881
+	| USER EQUAL ID         {
882
+		if (shm_initialized())
883
+			yyerror("user must be before any modparam or the"
884
+					" route blocks");
885
+		else if (user==0)
886
+			user=$3;
887
+	}
872 888
 	| USER EQUAL error      { yyerror("string value expected"); }
873 889
 	| GROUP EQUAL STRING     { group=$3; }
874 890
 	| GROUP EQUAL ID         { group=$3; }
... ...
@@ -1447,7 +1463,13 @@ assign_stm:
1447 1463
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1448 1464
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1449 1465
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1450
-	| SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
1466
+	| SHM_FORCE_ALLOC EQUAL NUMBER {
1467
+		if (shm_initialized())
1468
+			yyerror("shm_force_alloc must be before any modparam or the"
1469
+					" route blocks");
1470
+		else
1471
+			shm_force_alloc=$3;
1472
+	}
1451 1473
 	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1452 1474
 	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1453 1475
 	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
... ...
@@ -1560,11 +1582,23 @@ module_stm:
1560 1582
 	}
1561 1583
 	| LOADPATH EQUAL error	{ yyerror("string expected"); }
1562 1584
 	| MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1585
+	#ifdef SHM_MEM
1586
+		if (!shm_initialized() && init_shm()<0) {
1587
+			yyerror("Can't initialize shared memory");
1588
+			YYABORT;
1589
+		}
1590
+	#endif /* SHM_MEM */
1563 1591
 		if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1564 1592
 			 yyerror("Can't set module parameter");
1565 1593
 		}
1566 1594
 	}
1567
-        | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1595
+	| MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
1596
+	#ifdef SHM_MEM
1597
+		if (!shm_initialized() && init_shm()<0) {
1598
+			yyerror("Can't initialize shared memory");
1599
+			YYABORT;
1600
+		}
1601
+	#endif /* SHM_MEM */
1568 1602
 		if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1569 1603
 			 yyerror("Can't set module parameter");
1570 1604
 		}
... ...
@@ -1645,8 +1679,22 @@ route_name:		NUMBER	{
1645 1679
 ;
1646 1680
 
1647 1681
 route_stm:
1648
-	ROUTE LBRACE actions RBRACE { push($3, &main_rt.rlist[DEFAULT_RT]); }
1682
+	ROUTE LBRACE actions RBRACE {
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, &main_rt.rlist[DEFAULT_RT]);
1690
+	}
1649 1691
 	| ROUTE 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 */
1650 1698
 		i_tmp=route_get(&main_rt, $3);
1651 1699
 		if (i_tmp==-1){
1652 1700
 			yyerror("internal error");
... ...
@@ -1662,9 +1710,21 @@ route_stm:
1662 1710
 	;
1663 1711
 failure_route_stm:
1664 1712
 	ROUTE_FAILURE LBRACE actions RBRACE {
1665
-									push($3, &failure_rt.rlist[DEFAULT_RT]);
1666
-										}
1713
+	#ifdef SHM_MEM
1714
+		if (!shm_initialized() && init_shm()<0) {
1715
+			yyerror("Can't initialize shared memory");
1716
+			YYABORT;
1717
+		}
1718
+	#endif /* SHM_MEM */
1719
+		push($3, &failure_rt.rlist[DEFAULT_RT]);
1720
+	}
1667 1721
 	| ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1722
+	#ifdef SHM_MEM
1723
+		if (!shm_initialized() && init_shm()<0) {
1724
+			yyerror("Can't initialize shared memory");
1725
+			YYABORT;
1726
+		}
1727
+	#endif /* SHM_MEM */
1668 1728
 		i_tmp=route_get(&failure_rt, $3);
1669 1729
 		if (i_tmp==-1){
1670 1730
 			yyerror("internal error");
... ...
@@ -1680,9 +1740,21 @@ failure_route_stm:
1680 1740
 	;
1681 1741
 onreply_route_stm:
1682 1742
 	ROUTE_ONREPLY LBRACE actions RBRACE {
1683
-									push($3, &onreply_rt.rlist[DEFAULT_RT]);
1684
-										}
1743
+	#ifdef SHM_MEM
1744
+		if (!shm_initialized() && init_shm()<0) {
1745
+			yyerror("Can't initialize shared memory");
1746
+			YYABORT;
1747
+		}
1748
+	#endif /* SHM_MEM */
1749
+		push($3, &onreply_rt.rlist[DEFAULT_RT]);
1750
+	}
1685 1751
 	| ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
1752
+	#ifdef SHM_MEM
1753
+		if (!shm_initialized() && init_shm()<0) {
1754
+			yyerror("Can't initialize shared memory");
1755
+			YYABORT;
1756
+		}
1757
+	#endif /* SHM_MEM */
1686 1758
 		i_tmp=route_get(&onreply_rt, $3);
1687 1759
 		if (i_tmp==-1){
1688 1760
 			yyerror("internal error");
... ...
@@ -1698,9 +1770,21 @@ onreply_route_stm:
1698 1770
 	;
1699 1771
 branch_route_stm:
1700 1772
 	ROUTE_BRANCH LBRACE actions RBRACE {
1701
-									push($3, &branch_rt.rlist[DEFAULT_RT]);
1702
-										}
1773
+	#ifdef SHM_MEM
1774
+		if (!shm_initialized() && init_shm()<0) {
1775
+			yyerror("Can't initialize shared memory");
1776
+			YYABORT;
1777
+		}
1778
+	#endif /* SHM_MEM */
1779
+		push($3, &branch_rt.rlist[DEFAULT_RT]);
1780
+	}
1703 1781
 	| ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1782
+	#ifdef SHM_MEM
1783
+		if (!shm_initialized() && init_shm()<0) {
1784
+			yyerror("Can't initialize shared memory");
1785
+			YYABORT;
1786
+		}
1787
+	#endif /* SHM_MEM */
1704 1788
 		i_tmp=route_get(&branch_rt, $3);
1705 1789
 		if (i_tmp==-1){
1706 1790
 			yyerror("internal error");
... ...
@@ -1715,9 +1799,21 @@ branch_route_stm:
1715 1799
 	| ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1716 1800
 	;
1717 1801
 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1718
-									push($3, &onsend_rt.rlist[DEFAULT_RT]);
1719
-												}
1802
+	#ifdef SHM_MEM
1803
+		if (!shm_initialized() && init_shm()<0) {
1804
+			yyerror("Can't initialize shared memory");
1805
+			YYABORT;
1806
+		}
1807
+	#endif /* SHM_MEM */
1808
+		push($3, &onsend_rt.rlist[DEFAULT_RT]);
1809
+	}
1720 1810
 	| ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1811
+	#ifdef SHM_MEM
1812
+		if (!shm_initialized() && init_shm()<0) {
1813
+			yyerror("Can't initialize shared memory");
1814
+			YYABORT;
1815
+		}
1816
+	#endif /* SHM_MEM */
1721 1817
 		i_tmp=route_get(&onsend_rt, $3);
1722 1818
 		if (i_tmp==-1){
1723 1819
 			yyerror("internal error");
... ...
@@ -1732,6 +1828,12 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1732 1828
 	| ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
1733 1829
 	;
1734 1830
 event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1831
+	#ifdef SHM_MEM
1832
+		if (!shm_initialized() && init_shm()<0) {
1833
+			yyerror("Can't initialize shared memory");
1834
+			YYABORT;
1835
+		}
1836
+	#endif /* SHM_MEM */
1735 1837
 		i_tmp=route_get(&event_rt, $3);
1736 1838
 		if (i_tmp==-1){
1737 1839
 			yyerror("internal error");