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 531
 		
532 532
 		return udp_rcv_loop();
533 533
 	}else{
534
+		/* process_no now initialized to zero -- increase from now on
535
+		   as new processes are forked (while skipping 0 reserved for main ;
536
+		   not that with multiple listeners, more children processes will
537
+		   share the same process_no and the pids array will be rewritten
538
+		*/
534 539
 		for(r=0;r<sock_no;r++){
535 540
 			/* create the listening socket (for each address)*/
536 541
 			if (udp_init(&sock_info[r])==-1) goto error;
... ...
@@ -572,9 +581,10 @@ int main_loop()
572 572
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/
573 573
 		}
574 574
 	}
575
+	/* process_no is still at zero ... it was only updated in children */ 
576
+	process_no=children_no;
577
+
575 578
 	/*this is the main process*/
576
-	pids[process_no]=getpid();
577
-	process_bit = 0;
578 579
 	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
579 580
 	bind_idx=0;					/* if it does it will use the first address */
580 581
 	/* if configured to do so, start a server for accepting FIFO commands */
... ...
@@ -582,16 +592,16 @@ int main_loop()
582 582
 		LOG(L_ERR, "opening fifo server failed\n");
583 583
 		goto error;
584 584
 	}
585
-	is_main=1;
586 585
 
587 586
 	if (timer_list){
588 587
 		/* fork again for the attendant process*/
588
+		process_no++;
589 589
 		if ((pid=fork())<0){
590 590
 			LOG(L_CRIT, "main_loop: cannot fork timer process\n");
591 591
 			goto error;
592 592
 		}else if (pid==0){
593 593
 			/* child */
594
-			is_main=0; /* warning: we don't keep this process pid*/
594
+			/* is_main=0; */ /* warning: we don't keep this process pid*/
595 595
 			for(;;){
596 596
 				/* debug:  instead of doing something usefull */
597 597
 				/* (placeholder for timers, etc.) */
... ...
@@ -601,6 +611,11 @@ int main_loop()
601 601
 			}
602 602
 		}
603 603
 	}
604
+
605
+	process_no=0; /* main */
606
+	pids[process_no]=getpid();
607
+	process_bit = 0;
608
+	is_main=1;
604 609
 	
605 610
 	for(;;){
606 611
 			pause();