Browse code

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 authored on 29/08/2002 16:08:56
Showing 2 changed files
... ...
@@ -393,7 +393,7 @@ int open_fifo_server()
393 393
 		/* call per-child module initialization too -- some
394 394
 		   FIFO commands may need it
395 395
 		*/
396
-		if (init_child(0) < 0 ) {
396
+		if (init_child(process_no) < 0 ) {
397 397
 			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
398 398
 			return -1;
399 399
 		}
... ...
@@ -486,6 +486,10 @@ int main_loop()
486 486
 			LOG(L_WARN, "WARNING: using only the first listen address (no fork)\n");
487 487
 		}
488 488
 
489
+		/* process_no now initialized to zero -- increase from now on
490
+		   as new processes are forked (while skipping 0 reserved for main 
491
+		*/
492
+
489 493
 		/* we need another process to act as the timer*/
490 494
 		if (timer_list){
491 495
 				process_no++;
... ...
@@ -531,6 +535,11 @@ int main_loop()
531 535
 		
532 536
 		return udp_rcv_loop();
533 537
 	}else{
538
+		/* process_no now initialized to zero -- increase from now on
539
+		   as new processes are forked (while skipping 0 reserved for main ;
540
+		   not that with multiple listeners, more children processes will
541
+		   share the same process_no and the pids array will be rewritten
542
+		*/
534 543
 		for(r=0;r<sock_no;r++){
535 544
 			/* create the listening socket (for each address)*/
536 545
 			if (udp_init(&sock_info[r])==-1) goto error;
... ...
@@ -572,9 +581,10 @@ int main_loop()
572 581
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/
573 582
 		}
574 583
 	}
584
+	/* process_no is still at zero ... it was only updated in children */ 
585
+	process_no=children_no;
586
+
575 587
 	/*this is the main process*/
576
-	pids[process_no]=getpid();
577
-	process_bit = 0;
578 588
 	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
579 589
 	bind_idx=0;					/* if it does it will use the first address */
580 590
 	/* if configured to do so, start a server for accepting FIFO commands */
... ...
@@ -582,16 +592,16 @@ int main_loop()
582 592
 		LOG(L_ERR, "opening fifo server failed\n");
583 593
 		goto error;
584 594
 	}
585
-	is_main=1;
586 595
 
587 596
 	if (timer_list){
588 597
 		/* fork again for the attendant process*/
598
+		process_no++;
589 599
 		if ((pid=fork())<0){
590 600
 			LOG(L_CRIT, "main_loop: cannot fork timer process\n");
591 601
 			goto error;
592 602
 		}else if (pid==0){
593 603
 			/* child */
594
-			is_main=0; /* warning: we don't keep this process pid*/
604
+			/* is_main=0; */ /* warning: we don't keep this process pid*/
595 605
 			for(;;){
596 606
 				/* debug:  instead of doing something usefull */
597 607
 				/* (placeholder for timers, etc.) */
... ...
@@ -601,6 +611,11 @@ int main_loop()
601 611
 			}
602 612
 		}
603 613
 	}
614
+
615
+	process_no=0; /* main */
616
+	pids[process_no]=getpid();
617
+	process_bit = 0;
618
+	is_main=1;
604 619
 	
605 620
 	for(;;){
606 621
 			pause();