Jelajahi Sumber

process_no assignment made more consistent -- that also fixed
a problem with fifo_server calling init_child(0), which some
modules expected to receive only once

Jiri Kuthan 23 tahun lalu
induk
melakukan
db2494508f
2 mengubah file dengan 20 tambahan dan 5 penghapusan
  1. 1 1
      fifo_server.c
  2. 19 4
      main.c

+ 1 - 1
fifo_server.c

@@ -393,7 +393,7 @@ int open_fifo_server()
 		/* call per-child module initialization too -- some
 		/* call per-child module initialization too -- some
 		   FIFO commands may need it
 		   FIFO commands may need it
 		*/
 		*/
-		if (init_child(0) < 0 ) {
+		if (init_child(process_no) < 0 ) {
 			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
 			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
 			return -1;
 			return -1;
 		}
 		}

+ 19 - 4
main.c

@@ -486,6 +486,10 @@ int main_loop()
 			LOG(L_WARN, "WARNING: using only the first listen address (no fork)\n");
 			LOG(L_WARN, "WARNING: using only the first listen address (no fork)\n");
 		}
 		}
 
 
+		/* process_no now initialized to zero -- increase from now on
+		   as new processes are forked (while skipping 0 reserved for main 
+		*/
+
 		/* we need another process to act as the timer*/
 		/* we need another process to act as the timer*/
 		if (timer_list){
 		if (timer_list){
 				process_no++;
 				process_no++;
@@ -531,6 +535,11 @@ int main_loop()
 		
 		
 		return udp_rcv_loop();
 		return udp_rcv_loop();
 	}else{
 	}else{
+		/* process_no now initialized to zero -- increase from now on
+		   as new processes are forked (while skipping 0 reserved for main ;
+		   not that with multiple listeners, more children processes will
+		   share the same process_no and the pids array will be rewritten
+		*/
 		for(r=0;r<sock_no;r++){
 		for(r=0;r<sock_no;r++){
 			/* create the listening socket (for each address)*/
 			/* create the listening socket (for each address)*/
 			if (udp_init(&sock_info[r])==-1) goto error;
 			if (udp_init(&sock_info[r])==-1) goto error;
@@ -572,9 +581,10 @@ int main_loop()
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/
 		}
 		}
 	}
 	}
+	/* process_no is still at zero ... it was only updated in children */ 
+	process_no=children_no;
+
 	/*this is the main process*/
 	/*this is the main process*/
-	pids[process_no]=getpid();
-	process_bit = 0;
 	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
 	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
 	bind_idx=0;					/* if it does it will use the first address */
 	bind_idx=0;					/* if it does it will use the first address */
 	/* if configured to do so, start a server for accepting FIFO commands */
 	/* if configured to do so, start a server for accepting FIFO commands */
@@ -582,16 +592,16 @@ int main_loop()
 		LOG(L_ERR, "opening fifo server failed\n");
 		LOG(L_ERR, "opening fifo server failed\n");
 		goto error;
 		goto error;
 	}
 	}
-	is_main=1;
 
 
 	if (timer_list){
 	if (timer_list){
 		/* fork again for the attendant process*/
 		/* fork again for the attendant process*/
+		process_no++;
 		if ((pid=fork())<0){
 		if ((pid=fork())<0){
 			LOG(L_CRIT, "main_loop: cannot fork timer process\n");
 			LOG(L_CRIT, "main_loop: cannot fork timer process\n");
 			goto error;
 			goto error;
 		}else if (pid==0){
 		}else if (pid==0){
 			/* child */
 			/* child */
-			is_main=0; /* warning: we don't keep this process pid*/
+			/* is_main=0; */ /* warning: we don't keep this process pid*/
 			for(;;){
 			for(;;){
 				/* debug:  instead of doing something usefull */
 				/* debug:  instead of doing something usefull */
 				/* (placeholder for timers, etc.) */
 				/* (placeholder for timers, etc.) */
@@ -601,6 +611,11 @@ int main_loop()
 			}
 			}
 		}
 		}
 	}
 	}
+
+	process_no=0; /* main */
+	pids[process_no]=getpid();
+	process_bit = 0;
+	is_main=1;
 	
 	
 	for(;;){
 	for(;;){
 			pause();
 			pause();