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