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

Jan Janak authored on 06/04/2003 20:28:12
Showing 5 changed files
... ...
@@ -540,7 +540,7 @@ int open_fifo_server()
540 540
 		close(sockfd[0]);
541 541
 		unix_tcp_sock=sockfd[1];
542 542
 #endif
543
-		if (init_child(process_no) < 0 ) {
543
+		if (init_child(PROC_FIFO) < 0 ) {
544 544
 			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
545 545
 			return -1;
546 546
 		}
... ...
@@ -31,6 +31,7 @@
31 31
  *  2003-03-19  replaced all malloc/frees w/ pkg_malloc/pkg_free (andrei)
32 32
  *  2003-03-29  pkg cleaners for fifo and script callbacks introduced (jiri)
33 33
  *  2003-03-31  removed snmp part (obsolete & no place in core) (andrei)
34
+ *  2003-04-06  child_init called in all processes (janakj)
34 35
  *
35 36
  */
36 37
 
... ...
@@ -640,6 +641,10 @@ int main_loop()
640 640
 					/* child */
641 641
 					/* timer!*/
642 642
 					/* process_bit = 0; */
643
+					if (init_child(PROC_TIMER) < 0) {
644
+						LOG(L_ERR, "timer: init_child failed\n");
645
+						goto error;
646
+					}
643 647
 					for(;;){
644 648
 						sleep(TIMER_TICK);
645 649
 						timer_ticker();
... ...
@@ -664,11 +669,12 @@ int main_loop()
664 664
 		
665 665
 		
666 666
 		     /* We will call child_init even if we
667
-		      * do not fork
667
+		      * do not fork - and it will be called with rank 1 because
668
+		      * in fact we behave like a child, not like main process
668 669
 		      */
669 670
 
670
-		if (init_child(0) < 0) {
671
-			LOG(L_ERR, "init_child failed\n");
671
+		if (init_child(1) < 0) {
672
+			LOG(L_ERR, "main_dontfork: init_child failed\n");
672 673
 			goto error;
673 674
 		}
674 675
 
... ...
@@ -729,7 +735,7 @@ int main_loop()
729 729
 #endif
730 730
 					bind_address=&sock_info[r]; /* shortcut */
731 731
 					bind_idx=r;
732
-					if (init_child(i) < 0) {
732
+					if (init_child(i + 1) < 0) {
733 733
 						LOG(L_ERR, "init_child failed\n");
734 734
 						goto error;
735 735
 					}
... ...
@@ -817,6 +823,10 @@ int main_loop()
817 817
 		}else if (pid==0){
818 818
 			/* child */
819 819
 			/* is_main=0; */
820
+			if (init_child(PROC_TCP_MAIN) < 0) {
821
+				LOG(L_ERR, "tcp_main: error in init_child\n");
822
+				goto error;
823
+			}
820 824
 			tcp_main_loop();
821 825
 		}else{
822 826
 			pt[process_no].pid=pid;
... ...
@@ -847,6 +857,10 @@ int main_loop()
847 847
 	/* process_bit = 0; */
848 848
 	is_main=1;
849 849
 	
850
+	if (init_child(PROC_MAIN) < 0) {
851
+		LOG(L_ERR, "main: error in init_child\n");
852
+		goto error;
853
+	}
850 854
 	for(;;){
851 855
 			pause();
852 856
 			handle_sigs();
... ...
@@ -306,6 +306,17 @@ int init_modules(void)
306 306
 int init_child(int rank)
307 307
 {
308 308
 	struct sr_module* t;
309
+	char* type;
310
+
311
+	switch(rank) {
312
+	case PROC_MAIN:     type = "PROC_MAIN";     break;
313
+	case PROC_TIMER:    type = "PROC_TIMER";    break;
314
+	case PROC_FIFO:     type = "PROC_FIFO";     break;
315
+	case PROC_TCP_MAIN: type = "PROC_TCP_MAIN"; break;
316
+	default:            type = "CHILD";         break;
317
+	}
318
+	DBG("init_child: initializing %s with rank %d\n", type, rank);
319
+	
309 320
 
310 321
 	for(t = modules; t; t = t->next) {
311 322
 		if (t->exports->init_child_f) {
... ...
@@ -55,10 +55,15 @@ typedef enum {
55 55
 	INT_PARAM,  /* Integer parameter type */
56 56
 } modparam_t;       /* Allowed types of parameters */
57 57
 
58
-
59 58
 #define REQUEST_ROUTE 1         /* Function can be used in request route blocks */
60 59
 #define REPLY_ROUTE 2           /* Function can be used in reply route blocks */
61 60
 
61
+/* Macros - used as rank in child_init function */
62
+#define PROC_MAIN      0  /* Main ser process */
63
+#define PROC_TIMER    -1  /* Timer attendant process */
64
+#define PROC_FIFO     -2  /* FIFO attendant process */
65
+#define PROC_TCP_MAIN -4  /* TCP main process */
66
+
62 67
 struct cmd_export_ {
63 68
 	char* name;             /* null terminated command name */
64 69
 	cmd_function function;  /* pointer to the corresponding function */
... ...
@@ -947,8 +947,8 @@ int tcp_init_children()
947 947
 			bind_address=0; /* force a SEGFAULT if someone uses a non-init.
948 948
 							   bind address on tcp */
949 949
 			bind_idx=0;
950
-			if (init_child(r+children_no) < 0) {
951
-				LOG(L_ERR, "init_child failed\n");
950
+			if (init_child(r+children_no+1) < 0) {
951
+				LOG(L_ERR, "init_children failed\n");
952 952
 				goto error;
953 953
 			}
954 954
 			tcp_receive_loop(sockfd[1]);