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 341
 					goto error;
342 342
 				}
343 343
 				if (pid==0){
344
-					/* child */
344
+					     /* child */
345
+					if (init_child(i) < 0) {
346
+						LOG(L_ERR, "init_child failed\n");
347
+						goto error;
348
+					}
345 349
 					process_no=i+1; /*0=main*/
346 350
 					process_bit = 1 << i;
347 351
 #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 29
 	#ifdef STATIC_MAXFWD
30 30
 		register_module(maxfwd_mod_register, "built-in", 0);
31 31
 	#endif
32
+
33
+#ifdef STATIC_AUTH
34
+		register_module(tm_mod_register, "built-in", 0);
35
+#endif
36
+
37
+#ifdef STATIC_RR
38
+		register_module(rr_mod_register, "built-in", 0);
39
+#endif
40
+
41
+#ifdef STATIC_USRLOC
42
+		register_module(usrloc_mod_register, "built-in", 0);
43
+#endif
32 44
 }
33 45
 
34 46
 
... ...
@@ -64,6 +85,24 @@ error:
64 64
 	return ret;
65 65
 }
66 66
 
67
+/*
68
+ * per-child initialization
69
+ */
70
+int init_child(int rank)
71
+{
72
+	struct sr_module* t;
73
+
74
+	for(t = modules; t; t = t->next) {
75
+		if (t->exports->init_child_f) {
76
+			if ((t->exports->init_child_f(rank)) < 0) {
77
+				LOG(L_ERR, "init_child(): Initialization of child with rank %d failed\n");
78
+				return -1;
79
+			}
80
+		}
81
+	}
82
+	return 0;
83
+}
84
+
67 85
 
68 86
 
69 87
 /* 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 31
 								  be "destroyed", e.g: on ser exit;
32 32
 								  can be null */
33 33
 	onbreak_function onbreak_f;
34
+	child_init_function init_child_f;  /* Function will be called by all processes after the fork */
34 35
 };
35 36
 
36 37
 struct sr_module{
... ...
@@ -48,6 +50,7 @@ int load_module(char* path);
48 48
 cmd_function find_export(char* name, int param_no);
49 49
 struct sr_module* find_module(void *f, int* r);
50 50
 void destroy_modules();
51
+int init_child(int rank);
51 52
 
52 53
 
53 54
 /* modules function prototypes: