Browse code

- child init called in all ser processes (main, timer, fifo, tcp_main, udp_children, tcp_children, tcp_main) - defined macros PROC_MAIN, PROC_TIMER, PROC_FIFO, PROC_TCP_MAIN - they substitute rank for special processes - listening children have rank 1 and higher - modified modules to use rank 1 instead of 0 (modules creating it's own children) - db connections are either not opened in mod_init or are closed immediately when needed (for example preloading data for all children from database)

Jan Janak authored on 06/04/2003 20:25:51
Showing 14 changed files
... ...
@@ -34,6 +34,7 @@
34 34
  * 2003-03-11: New module interface (janakj)
35 35
  * 2003-03-16: flags export parameter added (janakj)
36 36
  * 2003-04-04  grand acc cleanup (jiri)
37
+ * 2003-04-06: Opens database connection in child_init only (janakj)
37 38
  */
38 39
 
39 40
 
... ...
@@ -273,23 +274,11 @@ static int mod_init( void )
273 274
 		return -1;
274 275
 
275 276
 #ifdef SQL_ACC
276
-    if (db_url == NULL) {
277
-        LOG(L_ERR, "ERROR: acc:init_mod(): Use db_url parameter\n");
278
-		return -1;
279
-	}
280
-
281 277
 	if (bind_dbmod()) {
282 278
 		LOG(L_ERR, "ERROR: acc: init_child bind_db failed..."
283 279
 				"did you load a database module?\n");
284 280
 		return -1;
285 281
 	}
286
-	db_handle = db_init(db_url);
287
-	if (!db_handle) {
288
-        LOG(L_ERR, "ERROR: acc:init_child(): "
289
-				"Unable to connect database\n");
290
-		return -1;
291
-	} 
292
-	DBG("DEbug: mod_init(acc): db opened \n");
293 282
 #endif
294 283
 
295 284
 #ifdef RAD_ACC
... ...
@@ -314,8 +303,6 @@ static int mod_init( void )
314 303
 static int child_init(int rank)
315 304
 {
316 305
 #ifdef SQL_ACC
317
-	/* close parent's DB connection */
318
-	db_close(db_handle);
319 306
 	db_handle = db_init(db_url);
320 307
 	if (!db_handle) {
321 308
         LOG(L_ERR, "acc:init_child(): Unable to connect database\n");
... ...
@@ -129,10 +129,6 @@ struct module_exports exports = {
129 129
 
130 130
 static int child_init(int rank)
131 131
 {
132
-	if (db_url == 0) {
133
-		LOG(L_ERR, "auth:init_child(): Use db_url parameter\n");
134
-		return -1;
135
-	}
136 132
 	db_handle = db_init(db_url);
137 133
 	if (!db_handle) {
138 134
 		LOG(L_ERR, "auth:init_child(): Unable to connect database\n");
... ...
@@ -145,7 +141,7 @@ static int child_init(int rank)
145 141
 
146 142
 static int mod_init(void)
147 143
 {
148
-	printf("auth module - initializing\n");
144
+	DBG("auth module - initializing\n");
149 145
 	
150 146
 	     /* Find a database module */
151 147
 	if (bind_dbmod()) {
... ...
@@ -31,6 +31,7 @@
31 31
  * 2003-03-11: New module interface (janakj)
32 32
  * 2003-03-16: flags export parameter added (janakj)
33 33
  * 2003-04-05: default_uri #define used (jiri)
34
+ * 2003-04-06: db connection closed in mod_init (janakj)
34 35
  */
35 36
 
36 37
 
... ...
@@ -107,7 +108,7 @@ static int mod_init(void)
107 108
 {
108 109
 	int i;
109 110
 
110
-	fprintf(stderr, "domain - initializing\n");
111
+	DBG("domain - initializing\n");
111 112
 	
112 113
 	/* Check if database module has been loaded */
113 114
 	if (bind_dbmod()) {
... ...
@@ -147,6 +148,8 @@ static int mod_init(void)
147 148
 			LOG(L_CRIT, "domain:mod_init(): Domain table reload failed\n");
148 149
 			return -1;
149 150
 		}
151
+			
152
+		db_close(db_handle);
150 153
 	}
151 154
 
152 155
 	return 0;
... ...
@@ -157,11 +160,6 @@ static int child_init(int rank)
157 160
 {
158 161
 	/* Check if database is needed by child */
159 162
 	if (db_mode == 0) {
160
-		if (db_url == NULL) {
161
-			LOG(L_ERR, "domain:child_init(): Use db_url parameter\n");
162
-			return -1;
163
-		}
164
-
165 163
 		db_handle = db_init(db_url);
166 164
 		if (!db_handle) {
167 165
 			LOG(L_ERR, "domain:child_init(): Unable to connect database\n");
... ...
@@ -170,7 +168,6 @@ static int child_init(int rank)
170 168
 	}
171 169
 
172 170
 	return 0;
173
-
174 171
 }
175 172
 
176 173
 
... ...
@@ -98,7 +98,7 @@ struct module_exports exports = {
98 98
 
99 99
 static int mod_init(void)
100 100
 {
101
-	printf("enum module - initializing\n");
101
+	DBG("enum module - initializing\n");
102 102
 	
103 103
 	suffix.s = domain_suffix;
104 104
 	suffix.len = strlen(suffix.s);
... ...
@@ -93,7 +93,7 @@ struct module_exports exports = {
93 93
 
94 94
 static int ext_child_init(int child)
95 95
 {
96
-	return init_ext();
96
+	return init_ext(child);
97 97
 }
98 98
 
99 99
 
... ...
@@ -86,14 +86,16 @@ static void sig_chld(int signo)
86 86
 
87 87
 
88 88
 
89
-int init_ext()
89
+int init_ext(int rank)
90 90
 {
91
-	if (signal(SIGCHLD,sig_chld)==SIG_ERR)
92
-		return -1;
93
-
94
-	_private_prog.pid = 0;
95
-	_private_prog.stat = 0;
96
-	return 1;
91
+	if (rank > 0) {
92
+		if (signal(SIGCHLD,sig_chld)==SIG_ERR)
93
+			return -1;
94
+		
95
+		_private_prog.pid = 0;
96
+		_private_prog.stat = 0;
97
+	}
98
+       return 1;
97 99
 }
98 100
 
99 101
 
... ...
@@ -44,7 +44,7 @@ struct program
44 44
 };
45 45
 
46 46
 
47
-int init_ext();
47
+int init_ext(int rank);
48 48
 int start_prog( char *cmd );
49 49
 int kill_prog();
50 50
 
... ...
@@ -124,11 +124,6 @@ struct module_exports exports = {
124 124
 
125 125
 static int child_init(int rank)
126 126
 {
127
-	if (db_url == 0) {
128
-		LOG(L_ERR, "group:init_child(): Use db_url parameter\n");
129
-		return -1;
130
-	}
131
-
132 127
 	db_handle = db_init(db_url);
133 128
 	if (!db_handle) {
134 129
 		LOG(L_ERR, "group:init_child(): Unable to connect database\n");
... ...
@@ -141,7 +136,7 @@ static int child_init(int rank)
141 136
 
142 137
 static int mod_init(void)
143 138
 {
144
-	printf("group module - initializing\n");
139
+	DBG("group module - initializing\n");
145 140
 	
146 141
 	     /* Find a database module */
147 142
 	if (bind_dbmod()) {
... ...
@@ -36,7 +36,7 @@
36 36
  * 2003-02-13 lot of comments enclosed in #ifdef XJ_EXTRA_DEBUG (dcm)
37 37
  * 2003-03-11 New module interface (janakj)
38 38
  * 2003-03-16 flags export parameter added (janakj)
39
- *
39
+ * 2003-04-06 rank 0 changed to 1 in child_init (janakj)
40 40
  */
41 41
 
42 42
 
... ...
@@ -297,7 +297,8 @@ static int child_init(int rank)
297 297
 	int i, j, mpid, cpid;
298 298
 	
299 299
 	DBG("XJAB:child_init: initializing child <%d>\n", rank);
300
-	if(rank == 0)
300
+	     /* Rank 0 is main process now - 1 is the first child (janakj) */
301
+	if(rank == 1)
301 302
 	{
302 303
 #ifdef HAVE_IHTTP
303 304
 		/** register iHTTP callbacks -- go forward in any case*/
... ...
@@ -33,6 +33,7 @@
33 33
  *             removed non-constant intializers to some strs (andrei)
34 34
  * 2003-03-16  flags parameter added (janakj)
35 35
  * 2003-04-05: default_uri #define used (jiri)
36
+ * 2003-04-06: db_init removed from mod_init, will be called from child_init now (janakj)
36 37
  */
37 38
 
38 39
 #include <stdio.h>
... ...
@@ -212,18 +213,6 @@ static int mod_init(void)
212 213
 	}
213 214
 	register_timer( m_clean_silo, 0, check_time);
214 215
 
215
-	db_con = db_init(db_url);
216
-	if (!db_con)
217
-	{
218
-		LOG(L_ERR,"MSILO: mod_init: Error while connecting database\n");
219
-		return -1;
220
-	}
221
-	else
222
-	{
223
-		db_use_table(db_con, db_table);
224
-		DBG("MSILO: mod_init: Database connection opened successfully\n");
225
-	}
226
-
227 216
 	reg_addr.s = registrar;
228 217
 	reg_addr.len = (registrar)?strlen(registrar):0;
229 218
 
... ...
@@ -76,6 +76,6 @@ struct module_exports exports = {
76 76
 
77 77
 static int mod_init(void)
78 78
 {
79
-	fprintf(stderr, "mysql - initializing\n");
79
+	DBG("mysql - initializing\n");
80 80
 	return 0;
81 81
 }
... ...
@@ -21,6 +21,10 @@
21 21
  * You should have received a copy of the GNU General Public License
22 22
  * along with this program; if not, write to the Free Software
23 23
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ *
25
+ * History:
26
+ * -------
27
+ * 2003-04-06: db connection closed in mod_init (janakj)
24 28
  */
25 29
 
26 30
 /*
... ...
@@ -258,7 +262,6 @@ static int mod_init(void)
258 262
 		db_use_table(db_con, db_table);
259 263
 		DBG("PDT: mod_init: Database connection opened successfully\n");
260 264
 	}
261
-
262 265
 	
263 266
 	/* init hashes */
264 267
 	if( (dhash = init_hash(hash_size)) == NULL )
... ...
@@ -328,6 +331,7 @@ static int mod_init(void)
328 331
 		goto error;
329 332
 	}
330 333
 
334
+	db_close(db_con); /* janakj - close the connection */
331 335
 	/* success code */
332 336
 	return 0;
333 337
 
... ...
@@ -32,6 +32,7 @@
32 32
  *  2003-03-16  flags export parameter added (janakj)
33 33
  *  2003-03-19  all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei)
34 34
  *  2003-04-02  port_no_str does not contain a leading ':' anymore (andrei)
35
+ *  2003-04-06  Only child 1 will execute child init (janakj)
35 36
  */
36 37
 
37 38
 
... ...
@@ -600,9 +601,8 @@ int sms_child_init(int rank)
600 601
 {
601 602
 	int  i, foo;
602 603
 
603
-	/* only the child 0 will execut this */
604
-	if (rank)
605
-		goto done;
604
+	/* only the child 1 will execut this */
605
+	if (rank != 1) goto done;
606 606
 
607 607
 	/* creats processes for each modem */
608 608
 	for(i=0;i<nr_of_modems;i++)
... ...
@@ -174,11 +174,6 @@ static int vm_init_child(int rank)
174 174
 {
175 175
     LOG(L_INFO,"voicemail - initializing child %i\n",rank);
176 176
 
177
-    if( !db_init && bind_dbmod() ){
178
-		LOG(L_CRIT, "cannot bind db_mod\n");
179
-		return -1;
180
-    }
181
-
182 177
     assert(db_init);
183 178
 
184 179
     db_handle=db_init(vm_db_url);