Răsfoiți Sursa

init_child support

Jan Janak 23 ani în urmă
părinte
comite
192ac55be1
3 a modificat fișierele cu 56 adăugiri și 1 ștergeri
  1. 14 1
      main.c
  2. 39 0
      sr_module.c
  3. 3 0
      sr_module.h

+ 14 - 1
main.c

@@ -330,6 +330,15 @@ int main_loop()
 		pids[0]=getpid();
 		process_bit = 1;
 		process_no=0; /*main process number*/
+		
+		     /* We will call child_init even if we
+		      * do not fork
+		      */
+		if (init_child(0) < 0) {
+			LOG(L_ERR, "init_child failed\n");
+			goto error;
+		}
+		
 		return udp_rcv_loop();
 	}else{
 		for(r=0;r<addresses_no;r++){
@@ -341,7 +350,11 @@ int main_loop()
 					goto error;
 				}
 				if (pid==0){
-					/* child */
+					     /* child */
+					if (init_child(i) < 0) {
+						LOG(L_ERR, "init_child failed\n");
+						goto error;
+					}
 					process_no=i+1; /*0=main*/
 					process_bit = 1 << i;
 #ifdef STATS

+ 39 - 0
sr_module.c

@@ -18,6 +18,15 @@ struct sr_module* modules=0;
 #ifdef STATIC_MAXFWD
 	extern struct module_exports* maxfwd_mod_register();
 #endif
+#ifdef STATIC_AUTH
+        extern struct module_exports* auth_mod_register();
+#endif
+#ifdef STATIC_RR
+        extern struct module_exports* rr_mod_register();
+#endif
+#ifdef STATIC_USRLOC
+        extern struct module_exports* usrloc_mod_register();
+#endif
 
 
 /* initializes statically built (compiled in) modules*/
@@ -29,6 +38,18 @@ int init_builtin_modules()
 	#ifdef STATIC_MAXFWD
 		register_module(maxfwd_mod_register, "built-in", 0);
 	#endif
+
+#ifdef STATIC_AUTH
+		register_module(tm_mod_register, "built-in", 0);
+#endif
+
+#ifdef STATIC_RR
+		register_module(rr_mod_register, "built-in", 0);
+#endif
+
+#ifdef STATIC_USRLOC
+		register_module(usrloc_mod_register, "built-in", 0);
+#endif
 }
 
 
@@ -64,6 +85,24 @@ error:
 	return ret;
 }
 
+/*
+ * per-child initialization
+ */
+int init_child(int rank)
+{
+	struct sr_module* t;
+
+	for(t = modules; t; t = t->next) {
+		if (t->exports->init_child_f) {
+			if ((t->exports->init_child_f(rank)) < 0) {
+				LOG(L_ERR, "init_child(): Initialization of child with rank %d failed\n");
+				return -1;
+			}
+		}
+	}
+	return 0;
+}
+
 
 
 /* returns 0 on success , <0 on error */

+ 3 - 0
sr_module.h

@@ -14,6 +14,7 @@ typedef  int (*fixup_function)(void** param, int param_no);
 typedef  int (*response_function)(struct sip_msg*);
 typedef  void (*onbreak_function)(struct sip_msg*);
 typedef void (*destroy_function)();
+typedef int (*child_init_function)(int rank);
 
 struct module_exports{
 	char* name; /* null terminated module name */
@@ -31,6 +32,7 @@ struct module_exports{
 								  be "destroyed", e.g: on ser exit;
 								  can be null */
 	onbreak_function onbreak_f;
+	child_init_function init_child_f;  /* Function will be called by all processes after the fork */
 };
 
 struct sr_module{
@@ -48,6 +50,7 @@ int load_module(char* path);
 cmd_function find_export(char* name, int param_no);
 struct sr_module* find_module(void *f, int* r);
 void destroy_modules();
+int init_child(int rank);
 
 
 /* modules function prototypes: