Browse code

- fixed pids & process_no

Andrei Pelinescu-Onciul authored on 10/09/2002 14:29:13
Showing 1 changed files
... ...
@@ -563,6 +563,7 @@ int main_loop()
563 563
 		}
564 564
 		for(r=0; r<sock_no;r++){
565 565
 			for(i=0;i<children_no;i++){
566
+				process_no++;
566 567
 				if ((pid=fork())<0){
567 568
 					LOG(L_CRIT,  "main_loop: Cannot fork\n");
568 569
 					goto error;
... ...
@@ -574,23 +575,19 @@ int main_loop()
574 575
 						LOG(L_ERR, "init_child failed\n");
575 576
 						goto error;
576 577
 					}
577
-
578
-					process_no=i+1; /*0=main*/
579
-					process_bit = 1 << i;
578
+					process_bit = 1 << (i+r*children_no); /*or process_no-1*/
580 579
 #ifdef STATS
581
-					setstats( i );
580
+					setstats( i+r*children_no );
582 581
 #endif
583 582
 					return udp_rcv_loop();
584 583
 				}else{
585
-						pids[i+1]=pid; /*should be in shared mem.*/
584
+						pids[process_no]=pid; /*should be in shared mem.*/
586 585
 				}
587 586
 			}
588 587
 			/*parent*/
589 588
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/
590 589
 		}
591 590
 	}
592
-	/* process_no is still at zero ... it was only updated in children */ 
593
-	process_no=children_no;
594 591
 
595 592
 	/*this is the main process*/
596 593
 	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
... ...
@@ -609,7 +606,7 @@ int main_loop()
609 606
 			goto error;
610 607
 		}else if (pid==0){
611 608
 			/* child */
612
-			/* is_main=0; */ /* warning: we don't keep this process pid*/
609
+			/* is_main=0; */
613 610
 			for(;;){
614 611
 				/* debug:  instead of doing something usefull */
615 612
 				/* (placeholder for timers, etc.) */
... ...
@@ -617,11 +614,20 @@ int main_loop()
617 614
 				/* if we received a signal => TIMER_TICK may have not elapsed*/
618 615
 				timer_ticker();
619 616
 			}
617
+		}else{
618
+			pids[process_no]=pid;
620 619
 		}
621 620
 	}
622 621
 
623
-	process_no=0; /* main */
624
-	pids[process_no]=getpid();
622
+	/* main */
623
+	pids[0]=getpid();
624
+	/*DEBUG- remove it*/
625
+	printf("\n% 3d processes, % 3d children * % 3d listening addresses + main + fifo %s\n",
626
+			process_no+1, children_no, sock_no, (timer_list)?"+ timer":"");
627
+	for (r=0; r<=process_no; r++){
628
+		printf("% 3d   % 5d\n", r, pids[r]);
629
+	}
630
+	process_no=0; 
625 631
 	process_bit = 0;
626 632
 	is_main=1;
627 633
 	
... ...
@@ -1076,17 +1082,6 @@ int main(int argc, char** argv)
1076 1082
 #endif
1077 1083
 	
1078 1084
 	if (working_dir==0) working_dir="/";
1079
-	/*alloc pids*/
1080
-#ifdef SHM_MEM
1081
-	pids=shm_malloc(sizeof(int)*(children_no+1/*timer */+1/*fifo*/));
1082
-#else
1083
-	pids=malloc(sizeof(int)*(children_no+1));
1084
-#endif
1085
-	if (pids==0){
1086
-		fprintf(stderr, "ERROR: out  of memory\n");
1087
-		goto error;
1088
-	}
1089
-	memset(pids, 0, sizeof(int)*(children_no+1));
1090 1085
 
1091 1086
 	if (sock_no==0) {
1092 1087
 		/* try to get all listening ipv4 interfaces */
... ...
@@ -1235,8 +1230,27 @@ int main(int argc, char** argv)
1235 1230
 	printf("Aliases: ");
1236 1231
 	for(a=aliases; a; a=a->next) printf("%.*s ", a->alias.len, a->alias.s);
1237 1232
 	printf("\n");
1238
-
1239
-
1233
+	if (sock_no==0){
1234
+		fprintf(stderr, "ERROR: no listening sockets");
1235
+		goto error;
1236
+	}
1237
+	if (dont_fork){
1238
+		fprintf(stderr, "WARNING: no fork mode %s\n", 
1239
+				(sock_no>1)?" and more than one listen address found (will use only the"
1240
+				" the first one)":"");
1241
+	}
1242
+	
1243
+	/*alloc pids*/
1244
+#ifdef SHM_MEM
1245
+	pids=shm_malloc(sizeof(int)*(children_no*sock_no+1/*main*/+1/*timer */+1/*fifo*/));
1246
+#else
1247
+	pids=malloc(sizeof(int)*(children_no*sock_no+1+1+1));
1248
+#endif
1249
+	if (pids==0){
1250
+		fprintf(stderr, "ERROR: out  of memory\n");
1251
+		goto error;
1252
+	}
1253
+	memset(pids, 0, sizeof(int)*(children_no+1));
1240 1254
 	
1241 1255
 	/* init_daemon? */
1242 1256
 	if (!dont_fork){