Browse code

init_child support

Jan Janak authored on 01/03/2002 10:52:19
Showing 3 changed files
... ...
@@ -330,6 +330,15 @@ int main_loop()
330 330
 		pids[0]=getpid();
331 331
 		process_bit = 1;
332 332
 		process_no=0; /*main process number*/
333
+		
334
+		     /* We will call child_init even if we
335
+		      * do not fork
336
+		      */
337
+		if (init_child(0) < 0) {
338
+			LOG(L_ERR, "init_child failed\n");
339
+			goto error;
340
+		}
341
+		
333 342
 		return udp_rcv_loop();
334 343
 	}else{
335 344
 		for(r=0;r<addresses_no;r++){
... ...
@@ -341,7 +350,11 @@ int main_loop()
341 350
 					goto error;
342 351
 				}
343 352
 				if (pid==0){
344
-					/* child */
353
+					     /* child */
354
+					if (init_child(i) < 0) {
355
+						LOG(L_ERR, "init_child failed\n");
356
+						goto error;
357
+					}
345 358
 					process_no=i+1; /*0=main*/
346 359
 					process_bit = 1 << i;
347 360
 #ifdef STATS
... ...
@@ -18,6 +18,15 @@ struct sr_module* modules=0;
18 18
 #ifdef STATIC_MAXFWD
19 19
 	extern struct module_exports* maxfwd_mod_register();
20 20
 #endif
21
+#ifdef STATIC_AUTH
22
+        extern struct module_exports* auth_mod_register();
23
+#endif
24
+#ifdef STATIC_RR
25
+        extern struct module_exports* rr_mod_register();
26
+#endif
27
+#ifdef STATIC_USRLOC
28
+        extern struct module_exports* usrloc_mod_register();
29
+#endif
21 30
 
22 31
 
23 32
 /* initializes statically built (compiled in) modules*/
... ...
@@ -29,6 +38,18 @@ int init_builtin_modules()
29 38
 	#ifdef STATIC_MAXFWD
30 39
 		register_module(maxfwd_mod_register, "built-in", 0);
31 40
 	#endif
41
+
42
+#ifdef STATIC_AUTH
43
+		register_module(tm_mod_register, "built-in", 0);
44
+#endif
45
+
46
+#ifdef STATIC_RR
47
+		register_module(rr_mod_register, "built-in", 0);
48
+#endif
49
+
50
+#ifdef STATIC_USRLOC
51
+		register_module(usrloc_mod_register, "built-in", 0);
52
+#endif
32 53
 }
33 54
 
34 55
 
... ...
@@ -64,6 +85,24 @@ error:
64 85
 	return ret;
65 86
 }
66 87
 
88
+/*
89
+ * per-child initialization
90
+ */
91
+int init_child(int rank)
92
+{
93
+	struct sr_module* t;
94
+
95
+	for(t = modules; t; t = t->next) {
96
+		if (t->exports->init_child_f) {
97
+			if ((t->exports->init_child_f(rank)) < 0) {
98
+				LOG(L_ERR, "init_child(): Initialization of child with rank %d failed\n");
99
+				return -1;
100
+			}
101
+		}
102
+	}
103
+	return 0;
104
+}
105
+
67 106
 
68 107
 
69 108
 /* returns 0 on success , <0 on error */
... ...
@@ -14,6 +14,7 @@ typedef  int (*fixup_function)(void** param, int param_no);
14 14
 typedef  int (*response_function)(struct sip_msg*);
15 15
 typedef  void (*onbreak_function)(struct sip_msg*);
16 16
 typedef void (*destroy_function)();
17
+typedef int (*child_init_function)(int rank);
17 18
 
18 19
 struct module_exports{
19 20
 	char* name; /* null terminated module name */
... ...
@@ -31,6 +32,7 @@ struct module_exports{
31 32
 								  be "destroyed", e.g: on ser exit;
32 33
 								  can be null */
33 34
 	onbreak_function onbreak_f;
35
+	child_init_function init_child_f;  /* Function will be called by all processes after the fork */
34 36
 };
35 37
 
36 38
 struct sr_module{
... ...
@@ -48,6 +50,7 @@ int load_module(char* path);
48 50
 cmd_function find_export(char* name, int param_no);
49 51
 struct sr_module* find_module(void *f, int* r);
50 52
 void destroy_modules();
53
+int init_child(int rank);
51 54
 
52 55
 
53 56
 /* modules function prototypes: