2
0
Эх сурвалжийг харах

- 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 22 жил өмнө
parent
commit
cb87691afc
5 өөрчлөгдсөн 38 нэмэгдсэн , 8 устгасан
  1. 1 1
      fifo_server.c
  2. 18 4
      main.c
  3. 11 0
      sr_module.c
  4. 6 1
      sr_module.h
  5. 2 2
      tcp_main.c

+ 1 - 1
fifo_server.c

@@ -540,7 +540,7 @@ int open_fifo_server()
 		close(sockfd[0]);
 		unix_tcp_sock=sockfd[1];
 #endif
-		if (init_child(process_no) < 0 ) {
+		if (init_child(PROC_FIFO) < 0 ) {
 			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
 			return -1;
 		}

+ 18 - 4
main.c

@@ -31,6 +31,7 @@
  *  2003-03-19  replaced all malloc/frees w/ pkg_malloc/pkg_free (andrei)
  *  2003-03-29  pkg cleaners for fifo and script callbacks introduced (jiri)
  *  2003-03-31  removed snmp part (obsolete & no place in core) (andrei)
+ *  2003-04-06  child_init called in all processes (janakj)
  *
  */
 
@@ -640,6 +641,10 @@ int main_loop()
 					/* child */
 					/* timer!*/
 					/* process_bit = 0; */
+					if (init_child(PROC_TIMER) < 0) {
+						LOG(L_ERR, "timer: init_child failed\n");
+						goto error;
+					}
 					for(;;){
 						sleep(TIMER_TICK);
 						timer_ticker();
@@ -664,11 +669,12 @@ int main_loop()
 		
 		
 		     /* We will call child_init even if we
-		      * do not fork
+		      * do not fork - and it will be called with rank 1 because
+		      * in fact we behave like a child, not like main process
 		      */
 
-		if (init_child(0) < 0) {
-			LOG(L_ERR, "init_child failed\n");
+		if (init_child(1) < 0) {
+			LOG(L_ERR, "main_dontfork: init_child failed\n");
 			goto error;
 		}
 
@@ -729,7 +735,7 @@ int main_loop()
 #endif
 					bind_address=&sock_info[r]; /* shortcut */
 					bind_idx=r;
-					if (init_child(i) < 0) {
+					if (init_child(i + 1) < 0) {
 						LOG(L_ERR, "init_child failed\n");
 						goto error;
 					}
@@ -817,6 +823,10 @@ int main_loop()
 		}else if (pid==0){
 			/* child */
 			/* is_main=0; */
+			if (init_child(PROC_TCP_MAIN) < 0) {
+				LOG(L_ERR, "tcp_main: error in init_child\n");
+				goto error;
+			}
 			tcp_main_loop();
 		}else{
 			pt[process_no].pid=pid;
@@ -847,6 +857,10 @@ int main_loop()
 	/* process_bit = 0; */
 	is_main=1;
 	
+	if (init_child(PROC_MAIN) < 0) {
+		LOG(L_ERR, "main: error in init_child\n");
+		goto error;
+	}
 	for(;;){
 			pause();
 			handle_sigs();

+ 11 - 0
sr_module.c

@@ -306,6 +306,17 @@ int init_modules(void)
 int init_child(int rank)
 {
 	struct sr_module* t;
+	char* type;
+
+	switch(rank) {
+	case PROC_MAIN:     type = "PROC_MAIN";     break;
+	case PROC_TIMER:    type = "PROC_TIMER";    break;
+	case PROC_FIFO:     type = "PROC_FIFO";     break;
+	case PROC_TCP_MAIN: type = "PROC_TCP_MAIN"; break;
+	default:            type = "CHILD";         break;
+	}
+	DBG("init_child: initializing %s with rank %d\n", type, rank);
+	
 
 	for(t = modules; t; t = t->next) {
 		if (t->exports->init_child_f) {

+ 6 - 1
sr_module.h

@@ -55,10 +55,15 @@ typedef enum {
 	INT_PARAM,  /* Integer parameter type */
 } modparam_t;       /* Allowed types of parameters */
 
-
 #define REQUEST_ROUTE 1         /* Function can be used in request route blocks */
 #define REPLY_ROUTE 2           /* Function can be used in reply route blocks */
 
+/* Macros - used as rank in child_init function */
+#define PROC_MAIN      0  /* Main ser process */
+#define PROC_TIMER    -1  /* Timer attendant process */
+#define PROC_FIFO     -2  /* FIFO attendant process */
+#define PROC_TCP_MAIN -4  /* TCP main process */
+
 struct cmd_export_ {
 	char* name;             /* null terminated command name */
 	cmd_function function;  /* pointer to the corresponding function */

+ 2 - 2
tcp_main.c

@@ -947,8 +947,8 @@ int tcp_init_children()
 			bind_address=0; /* force a SEGFAULT if someone uses a non-init.
 							   bind address on tcp */
 			bind_idx=0;
-			if (init_child(r+children_no) < 0) {
-				LOG(L_ERR, "init_child failed\n");
+			if (init_child(r+children_no+1) < 0) {
+				LOG(L_ERR, "init_children failed\n");
 				goto error;
 			}
 			tcp_receive_loop(sockfd[1]);