Browse code

- command line options have higher priority than configuration script (-m -f ,etc.) - -h options recognized even in "-f -h" construction

Tomas Mandys authored on 10/01/2006 00:28:05
Showing 1 changed files
... ...
@@ -20,8 +20,8 @@
20 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 21
  * GNU General Public License for more details.
22 22
  *
23
- * You should have received a copy of the GNU General Public License 
24
- * along with this program; if not, write to the Free Software 
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  *
27 27
  * History:
... ...
@@ -32,10 +32,10 @@
32 32
  *  2003-03-29  pkg cleaners for fifo and script callbacks introduced (jiri)
33 33
  *  2003-03-31  removed snmp part (obsolete & no place in core) (andrei)
34 34
  *  2003-04-06  child_init called in all processes (janakj)
35
- *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and 
35
+ *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and
36 36
  *               init_shm_mallocs called after cmd. line parsing (andrei)
37 37
  *  2003-04-15  added tcp_disable support (andrei)
38
- *  2003-05-09  closelog() before openlog to force opening a new fd 
38
+ *  2003-05-09  closelog() before openlog to force opening a new fd
39 39
  *               (needed on solaris) (andrei)
40 40
  *  2003-06-11  moved all signal handlers init. in install_sigs and moved it
41 41
  *               after daemonize (so that we won't catch anymore our own
... ...
@@ -196,7 +196,7 @@ void print_ct_constants()
196 196
 */
197 197
 	printf("MAX_RECV_BUFFER_SIZE %d, MAX_LISTEN %d,"
198 198
 			" MAX_URI_SIZE %d, BUF_SIZE %d\n",
199
-		MAX_RECV_BUFFER_SIZE, MAX_LISTEN, MAX_URI_SIZE, 
199
+		MAX_RECV_BUFFER_SIZE, MAX_LISTEN, MAX_URI_SIZE,
200 200
 		BUF_SIZE );
201 201
 #ifdef USE_TCP
202 202
 	printf("poll method support: %s.\n", poll_support);
... ...
@@ -227,7 +227,7 @@ int own_pgid = 0; /* whether or not we have our own pgid (and it's ok
227 227
 char* cfg_file = 0;
228 228
 unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do
229 229
 												  not want to exceed during the
230
-												  auto-probing procedure; may 
230
+												  auto-probing procedure; may
231 231
 												  be re-configured */
232 232
 int children_no = 0;			/* number of children processing requests */
233 233
 #ifdef USE_TCP
... ...
@@ -247,7 +247,7 @@ int log_stderr = 0;
247 247
 int log_facility = LOG_DAEMON;
248 248
 int config_check = 0;
249 249
 /* check if reply first via host==us */
250
-int check_via =  0;        
250
+int check_via =  0;
251 251
 /* shall use stateful synonym branches? faster but not reboot-safe */
252 252
 int syn_branch = 1;
253 253
 /* debugging level for memory stats */
... ...
@@ -266,9 +266,9 @@ int server_signature=1;
266 266
  * host? by default not -- too expensive
267 267
  */
268 268
 int mhomed=0;
269
-/* use dns and/or rdns or to see if we need to add 
269
+/* use dns and/or rdns or to see if we need to add
270 270
    a ;received=x.x.x.x to via: */
271
-int received_dns = 0;      
271
+int received_dns = 0;
272 272
 char* working_dir = 0;
273 273
 char* chroot_dir = 0;
274 274
 char* user=0;
... ...
@@ -314,8 +314,8 @@ struct socket_info* bind_address=0; /* pointer to the crt. proc.
314 314
 struct socket_info* sendipv4; /* ipv4 socket to use when msg. comes from ipv6*/
315 315
 struct socket_info* sendipv6; /* same as above for ipv6 */
316 316
 #ifdef USE_TCP
317
-struct socket_info* sendipv4_tcp; 
318
-struct socket_info* sendipv6_tcp; 
317
+struct socket_info* sendipv4_tcp;
318
+struct socket_info* sendipv6_tcp;
319 319
 #endif
320 320
 #ifdef USE_TLS
321 321
 struct socket_info* sendipv4_tls;
... ...
@@ -372,9 +372,9 @@ char* pgid_file = 0;
372 372
 void cleanup(show_status)
373 373
 {
374 374
 	/*clean-up*/
375
-	if (mem_lock) 
375
+	if (mem_lock)
376 376
 		shm_unlock(); /* hack: force-unlock the shared memory lock in case
377
-					 some process crashed and let it locked; this will 
377
+					 some process crashed and let it locked; this will
378 378
 					 allow an almost gracious shutdown */
379 379
 	destroy_modules();
380 380
 #ifdef USE_TCP
... ...
@@ -409,12 +409,12 @@ void cleanup(show_status)
409 409
 /* tries to send a signal to all our processes
410 410
  * if daemonized  is ok to send the signal to all the process group,
411 411
  * however if not daemonized we might end up sending the signal also
412
- * to the shell which launched us => most signals will kill it if 
413
- * it's not in interactive mode and we don't want this. The non-daemonized 
414
- * case can occur when an error is encountered before daemonize is called 
412
+ * to the shell which launched us => most signals will kill it if
413
+ * it's not in interactive mode and we don't want this. The non-daemonized
414
+ * case can occur when an error is encountered before daemonize is called
415 415
  * (e.g. when parsing the config file) or when ser is started in "dont-fork"
416 416
  *  mode. Sending the signal to all the processes in pt[] will not work
417
- *  for processes forked from modules (which have no correspondent entry in 
417
+ *  for processes forked from modules (which have no correspondent entry in
418 418
  *  pt), but this can happen only in dont_fork mode (which is only for
419 419
  *  debugging). So in the worst case + "dont-fork" we might leave some
420 420
  *  zombies. -- andrei */
... ...
@@ -473,18 +473,18 @@ void handle_sigs()
473 473
 				DBG("INT received, program terminates\n");
474 474
 			else
475 475
 				DBG("SIGTERM received, program terminates\n");
476
-				
476
+
477 477
 			/* first of all, kill the children also */
478 478
 			kill_all_children(SIGTERM);
479 479
 
480 480
 			     /* Wait for all the children to die */
481 481
 			while(wait(0) > 0);
482
-			
482
+
483 483
 			cleanup(1); /* cleanup & show status*/
484 484
 			dprint("Thank you for flying " NAME "\n");
485 485
 			exit(0);
486 486
 			break;
487
-			
487
+
488 488
 		case SIGUSR1:
489 489
 #ifdef STATS
490 490
 			dump_all_statistic();
... ...
@@ -498,12 +498,12 @@ void handle_sigs()
498 498
 			shm_status();
499 499
 #endif
500 500
 			break;
501
-			
501
+
502 502
 		case SIGCHLD:
503 503
 			while ((chld=waitpid( -1, &chld_status, WNOHANG ))>0) {
504
-				if (WIFEXITED(chld_status)) 
504
+				if (WIFEXITED(chld_status))
505 505
 					LOG(L_INFO, "child process %d exited normally,"
506
-							" status=%d\n", chld, 
506
+							" status=%d\n", chld,
507 507
 							WEXITSTATUS(chld_status));
508 508
 				else if (WIFSIGNALED(chld_status)) {
509 509
 					LOG(L_INFO, "child process %d exited by a signal"
... ...
@@ -512,7 +512,7 @@ void handle_sigs()
512 512
 					LOG(L_INFO, "core was %sgenerated\n",
513 513
 							 WCOREDUMP(chld_status) ?  "" : "not " );
514 514
 #endif
515
-				}else if (WIFSTOPPED(chld_status)) 
515
+				}else if (WIFSTOPPED(chld_status))
516 516
 					LOG(L_INFO, "child process %d stopped by a"
517 517
 								" signal %d\n", chld,
518 518
 								 WSTOPSIG(chld_status));
... ...
@@ -521,7 +521,7 @@ void handle_sigs()
521 521
 			if (dont_fork) {
522 522
 				LOG(L_INFO, "INFO: dont_fork turned on, living on\n");
523 523
 				break;
524
-			} 
524
+			}
525 525
 			LOG(L_INFO, "INFO: terminating due to SIGCHLD\n");
526 526
 #endif
527 527
 			/* exit */
... ...
@@ -540,7 +540,7 @@ void handle_sigs()
540 540
 			DBG("terminating due to SIGCHLD\n");
541 541
 			exit(0);
542 542
 			break;
543
-		
543
+
544 544
 		case SIGHUP: /* ignoring it*/
545 545
 					DBG("SIGHUP received, ignoring it\n");
546 546
 					break;
... ...
@@ -555,7 +555,7 @@ void handle_sigs()
555 555
 /* added by jku; allows for regular exit on a specific signal;
556 556
    good for profiling which only works if exited regularly and
557 557
    not by default signal handlers
558
-    - modified by andrei: moved most of the stuff to handle_sigs, 
558
+    - modified by andrei: moved most of the stuff to handle_sigs,
559 559
        made it safer for the "fork" case
560 560
 */
561 561
 static void sig_usr(int signo)
... ...
@@ -566,7 +566,7 @@ static void sig_usr(int signo)
566 566
 		if (sig_flag==0) sig_flag=signo;
567 567
 		else /*  previous sig. not processed yet, ignoring? */
568 568
 			return; ;
569
-		if (dont_fork) 
569
+		if (dont_fork)
570 570
 				/* only one proc, doing everything from the sig handler,
571 571
 				unsafe, but this is only for debugging mode*/
572 572
 			handle_sigs();
... ...
@@ -689,10 +689,10 @@ static int parse_phostport(char* s, char** host, int* hlen, int* port,
689 689
 	char* p;
690 690
 	int bracket;
691 691
 	char* tmp;
692
-	
692
+
693 693
 	first=second=0;
694 694
 	bracket=0;
695
-	
695
+
696 696
 	/* find the first 2 ':', ignoring possible ipv6 addresses
697 697
 	 * (substrings between [])
698 698
 	 */
... ...
@@ -717,7 +717,7 @@ static int parse_phostport(char* s, char** host, int* hlen, int* port,
717 717
 	}
718 718
 	if (p==s) return -1;
719 719
 	if (*(p-1)==':') goto error_colons;
720
-	
720
+
721 721
 	if (first==0){ /* no ':' => only host */
722 722
 		*host=s;
723 723
 		*hlen=(int)(p-s);
... ...
@@ -800,7 +800,7 @@ int main_loop()
800 800
 		}
801 801
 		if (do_suid()==-1) goto error; /* try to drop privileges */
802 802
 		/* process_no now initialized to zero -- increase from now on
803
-		   as new processes are forked (while skipping 0 reserved for main 
803
+		   as new processes are forked (while skipping 0 reserved for main
804 804
 		*/
805 805
 
806 806
 #ifdef USE_SLOW_TIMER
... ...
@@ -819,14 +819,14 @@ int main_loop()
819 819
 						LOG(L_ERR, "slow timer: init_child failed\n");
820 820
 						goto error;
821 821
 					}
822
-					
822
+
823 823
 					if (arm_slow_timer()<0) goto error;
824 824
 					slow_timer_main();
825 825
 				}else{
826 826
 					pt[process_no].pid=pid; /*should be shared mem anyway*/
827 827
 					strncpy(pt[process_no].desc, "slow timer", MAX_PT_DESC );
828 828
 					slow_timer_pid=pid;
829
-					
829
+
830 830
 				}
831 831
 #endif
832 832
 				/* we need another process to act as the "main" timer*/
... ...
@@ -846,7 +846,7 @@ int main_loop()
846 846
 						LOG(L_ERR, "timer: init_child failed\n");
847 847
 						goto error;
848 848
 					}
849
-					
849
+
850 850
 					if (arm_timer()<0) goto error;
851 851
 					timer_main();
852 852
 				}else{
... ...
@@ -857,11 +857,11 @@ int main_loop()
857 857
 		/* main process, receive loop */
858 858
 		process_no=0; /*main process number*/
859 859
 		pt[process_no].pid=getpid();
860
-		snprintf(pt[process_no].desc, MAX_PT_DESC, 
861
-			"stand-alone receiver @ %s:%s", 
860
+		snprintf(pt[process_no].desc, MAX_PT_DESC,
861
+			"stand-alone receiver @ %s:%s",
862 862
 			 bind_address->name.s, bind_address->port_no_str.s );
863
-		
864
-		
863
+
864
+
865 865
 		     /* We will call child_init even if we
866 866
 		      * do not fork - and it will be called with rank 1 because
867 867
 		      * in fact we behave like a child, not like main process
... ...
@@ -874,7 +874,7 @@ int main_loop()
874 874
 
875 875
 		is_main=1; /* hack 42: call init_child with is_main=0 in case
876 876
 					 some modules wants to fork a child */
877
-		
877
+
878 878
 		return udp_rcv_loop();
879 879
 	}else{
880 880
 		/* process_no now initialized to zero -- increase from now on
... ...
@@ -970,7 +970,7 @@ int main_loop()
970 970
 				}else{
971 971
 						pt[process_no].pid=pid; /*should be in shared mem.*/
972 972
 						snprintf(pt[process_no].desc, MAX_PT_DESC,
973
-							"receiver child=%d sock= %s:%s", i, 	
973
+							"receiver child=%d sock= %s:%s", i,
974 974
 							si->name.s, si->port_no_str.s );
975 975
 #ifdef USE_TCP
976 976
 						if (!tcp_disable){
... ...
@@ -989,7 +989,7 @@ int main_loop()
989 989
 
990 990
 	/*this is the main process*/
991 991
 	bind_address=0;				/* main proc -> it shouldn't send anything, */
992
-	
992
+
993 993
 
994 994
 	{
995 995
 #ifdef USE_SLOW_TIMER
... ...
@@ -1038,7 +1038,7 @@ int main_loop()
1038 1038
 #endif
1039 1039
 		}
1040 1040
 #endif /* USE_SLOW_TIMER */
1041
-	
1041
+
1042 1042
 		/* fork again for the "main" timer process*/
1043 1043
 #ifdef USE_TCP
1044 1044
 		if (!tcp_disable){
... ...
@@ -1128,10 +1128,10 @@ int main_loop()
1128 1128
 	 * process table properly
1129 1129
 	 */
1130 1130
 	last_process = process_no;
1131
-	process_no=0; 
1131
+	process_no=0;
1132 1132
 	/* process_bit = 0; */
1133 1133
 	is_main=1;
1134
-	
1134
+
1135 1135
 	if (init_child(PROC_MAIN) < 0) {
1136 1136
 		LOG(L_ERR, "main: error in init_child\n");
1137 1137
 		goto error;
... ...
@@ -1148,8 +1148,8 @@ int main_loop()
1148 1148
 			pause();
1149 1149
 			handle_sigs();
1150 1150
 	}
1151
-	
1152
-	
1151
+
1152
+
1153 1153
 	/*return 0; */
1154 1154
  error:
1155 1155
 	is_main=1;  /* if we are here, we are the "main process",
... ...
@@ -1167,7 +1167,7 @@ static int calc_proc_no(void)
1167 1167
 {
1168 1168
 	int udp_listeners;
1169 1169
 	struct socket_info* si;
1170
-	
1170
+
1171 1171
 	for (si=udp_listen, udp_listeners=0; si; si=si->next, udp_listeners++);
1172 1172
 	return
1173 1173
 		     /* receivers and attendant */
... ...
@@ -1179,7 +1179,7 @@ static int calc_proc_no(void)
1179 1179
 		+ 1 /* slow timer process */
1180 1180
 #endif
1181 1181
 #ifdef USE_TCP
1182
-		+((!tcp_disable)?( 1/* tcp main */ + tcp_children_no ):0) 
1182
+		+((!tcp_disable)?( 1/* tcp main */ + tcp_children_no ):0)
1183 1183
 #endif
1184 1184
 		;
1185 1185
 }
... ...
@@ -1197,11 +1197,12 @@ int main(int argc, char** argv)
1197 1197
 	int ret;
1198 1198
 	unsigned int seed;
1199 1199
 	int rfd;
1200
+	int debug_save, debug_flag = 0;
1200 1201
 
1201 1202
 	/*init*/
1202 1203
 	ret=-1;
1203 1204
 	my_argc=argc; my_argv=argv;
1204
-	
1205
+
1205 1206
 	/*init pkg mallocs (before parsing cfg or cmd line !)*/
1206 1207
 	if (init_pkg_mallocs()==-1)
1207 1208
 		goto error;
... ...
@@ -1211,18 +1212,26 @@ int main(int argc, char** argv)
1211 1211
 		"DBG_MSG_QA enabled, ser may exit abruptly\n");
1212 1212
 #endif
1213 1213
 
1214
-
1215
-
1216
-	/* process command line (get port no, cfg. file path etc) */
1217
-	opterr=0;
1218
-	options=
1214
+	options=  "f:cm:dVhEb:l:n:vrRDTN:W:w:t:u:g:P:G:"
1219 1215
 #ifdef STATS
1220
-	"s:"
1216
+		"s:"
1221 1217
 #endif
1222
-	"f:cm:b:l:n:N:rRvdDETVhw:t:u:g:P:G:W:";
1223
-	
1224
-	while((c=getopt(argc,argv,options))!=-1){
1225
-		switch(c){
1218
+	;
1219
+	/* look if there is a -h, e.g. -f -h construction won't catch it later */
1220
+	opterr = 0;
1221
+	while((c=getopt(argc,argv,options))!=-1) {
1222
+		if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
1223
+			printf("version: %s\n", version);
1224
+			printf("%s",help_msg);
1225
+			exit(0);
1226
+			break;
1227
+		}
1228
+	}
1229
+	/* process command line (get port no, cfg. file path etc) */
1230
+	optind = 1;  /* reset getopt */
1231
+	/* switches required before script processing */
1232
+	while((c=getopt(argc,argv,options))!=-1) {
1233
+		switch(c) {
1226 1234
 			case 'f':
1227 1235
 					cfg_file=optarg;
1228 1236
 					break;
... ...
@@ -1230,11 +1239,6 @@ int main(int argc, char** argv)
1230 1230
 					config_check=1;
1231 1231
 					log_stderr=1; /* force stderr logging */
1232 1232
 					break;
1233
-			case 's':
1234
-				#ifdef STATS
1235
-					stat_file=optarg;
1236
-				#endif
1237
-					break;
1238 1233
 			case 'm':
1239 1234
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
1240 1235
 					if (tmp &&(*tmp)){
... ...
@@ -1245,7 +1249,116 @@ int main(int argc, char** argv)
1245 1245
 					LOG(L_INFO, "ser: shared memory: %ld bytes\n",
1246 1246
 									shm_mem_size );
1247 1247
 					break;
1248
+			case 'd':
1249
+					debug_flag = 1;
1250
+					debug++;
1251
+					break;
1252
+			case 'V':
1253
+					printf("version: %s\n", version);
1254
+					printf("flags: %s\n", flags );
1255
+					print_ct_constants();
1256
+					printf("%s\n",id);
1257
+					printf("%s compiled on %s with %s\n", __FILE__,
1258
+							compiled, COMPILER );
1248 1259
 
1260
+					exit(0);
1261
+					break;
1262
+			case 'E':
1263
+					log_stderr=1;
1264
+					break;
1265
+			case 'b':
1266
+			case 'l':
1267
+			case 'n':
1268
+			case 'v':
1269
+			case 'r':
1270
+			case 'R':
1271
+			case 'D':
1272
+			case 'T':
1273
+			case 'N':
1274
+			case 'W':
1275
+			case 'w':
1276
+			case 't':
1277
+			case 'u':
1278
+			case 'g':
1279
+			case 'P':
1280
+		        case 'G':
1281
+			case 's':
1282
+					break;
1283
+			case '?':
1284
+					if (isprint(optopt))
1285
+						fprintf(stderr, "Unknown option `-%c�. Use -h for help.\n", optopt);
1286
+					else
1287
+						fprintf(stderr,
1288
+								"Unknown option character `\\x%x�. Use -h for help.\n",
1289
+								optopt);
1290
+					goto error;
1291
+			case ':':
1292
+					fprintf(stderr,
1293
+								"Option `-%c� requires an argument. Use -h for help.\n",
1294
+								optopt);
1295
+					goto error;
1296
+			default:
1297
+					abort();
1298
+		}
1299
+	}
1300
+
1301
+	/* fill missing arguments with the default values*/
1302
+	if (cfg_file==0) cfg_file=CFG_FILE;
1303
+
1304
+	/* load config file or die */
1305
+	cfg_stream=fopen (cfg_file, "r");
1306
+	if (cfg_stream==0){
1307
+		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
1308
+				strerror(errno));
1309
+		goto error;
1310
+	}
1311
+
1312
+	/* seed the prng */
1313
+	/* try to use /dev/urandom if possible */
1314
+	seed=0;
1315
+	if ((rfd=open("/dev/urandom", O_RDONLY))!=-1){
1316
+try_again:
1317
+		if (read(rfd, (void*)&seed, sizeof(seed))==-1){
1318
+			if (errno==EINTR) goto try_again; /* interrupted by signal */
1319
+			LOG(L_WARN, "WARNING: could not read from /dev/urandom (%d)\n",
1320
+						errno);
1321
+		}
1322
+		DBG("read %u from /dev/urandom\n", seed);
1323
+			close(rfd);
1324
+	}else{
1325
+		LOG(L_WARN, "WARNING: could not open /dev/urandom (%d)\n", errno);
1326
+	}
1327
+	seed+=getpid()+time(0);
1328
+	DBG("seeding PRNG with %u\n", seed);
1329
+	srand(seed);
1330
+	DBG("test random number %u\n", rand());
1331
+
1332
+	/*register builtin  modules*/
1333
+	register_builtin_modules();
1334
+
1335
+	yyin=cfg_stream;
1336
+	debug_save = debug;
1337
+	if ((yyparse()!=0)||(cfg_errors)){
1338
+		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
1339
+		goto error;
1340
+	}
1341
+	if (debug_flag) debug = debug_save;
1342
+	print_rl();
1343
+
1344
+	/* options with higher priority than cfg file */
1345
+	optind = 1;  /* reset getopt */
1346
+	while((c=getopt(argc,argv,options))!=-1) {
1347
+		switch(c) {
1348
+			case 'f':
1349
+			case 'c':
1350
+			case 'm':
1351
+			case 'd':
1352
+			case 'V':
1353
+			case 'h':
1354
+					break;
1355
+			case 'E':
1356
+					log_stderr=1;	// use in both getopt switches
1357
+					break;
1249 1358
 			case 'b':
1250 1359
 					maxbuffer=strtol(optarg, &tmp, 10);
1251 1360
 					if (tmp &&(*tmp)){
... ...
@@ -1284,60 +1397,40 @@ int main(int argc, char** argv)
1284 1284
 					break;
1285 1285
 			case 'R':
1286 1286
 					received_dns|=DO_REV_DNS;
1287
-			case 'd':
1288
-					debug++;
1289 1287
 					break;
1290 1288
 			case 'D':
1291 1289
 					dont_fork=1;
1292 1290
 					break;
1293
-			case 'E':
1294
-					log_stderr=1;
1295
-					break;
1296 1291
 			case 'T':
1297
-#ifdef USE_TCP
1292
+				#ifdef USE_TCP
1298 1293
 					tcp_disable=1;
1299
-#else
1294
+				#else
1300 1295
 					fprintf(stderr,"WARNING: tcp support not compiled in\n");
1301
-#endif
1296
+				#endif
1302 1297
 					break;
1303 1298
 			case 'N':
1304
-#ifdef USE_TCP
1299
+				#ifdef USE_TCP
1305 1300
 					tcp_children_no=strtol(optarg, &tmp, 10);
1306 1301
 					if ((tmp==0) ||(*tmp)){
1307 1302
 						fprintf(stderr, "bad process number: -N %s\n",
1308 1303
 									optarg);
1309 1304
 						goto error;
1310 1305
 					}
1311
-#else
1306
+				#else
1312 1307
 					fprintf(stderr,"WARNING: tcp support not compiled in\n");
1313
-#endif
1308
+				#endif
1314 1309
 					break;
1315 1310
 			case 'W':
1316
-#ifdef USE_TCP
1311
+				#ifdef USE_TCP
1317 1312
 					tcp_poll_method=get_poll_type(optarg);
1318 1313
 					if (tcp_poll_method==POLL_NONE){
1319 1314
 						fprintf(stderr, "bad poll method name: -W %s\ntry "
1320 1315
 										"one of %s.\n", optarg, poll_support);
1321 1316
 						goto error;
1322 1317
 					}
1323
-#else
1318
+				#else
1324 1319
 					fprintf(stderr,"WARNING: tcp support not compiled in\n");
1325
-#endif
1326
-					break;
1327
-			case 'V':
1328
-					printf("version: %s\n", version);
1329
-					printf("flags: %s\n", flags );
1330
-					print_ct_constants();
1331
-					printf("%s\n",id);
1332
-					printf("%s compiled on %s with %s\n", __FILE__,
1333
-							compiled, COMPILER );
1334
-					
1335
-					exit(0);
1336
-					break;
1337
-			case 'h':
1338
-					printf("version: %s\n", version);
1339
-					printf("%s",help_msg);
1340
-					exit(0);
1320
+				#endif
1341 1321
 					break;
1342 1322
 			case 'w':
1343 1323
 					working_dir=optarg;
... ...
@@ -1357,66 +1450,16 @@ int main(int argc, char** argv)
1357 1357
 		        case 'G':
1358 1358
 				        pgid_file=optarg;
1359 1359
 				        break;
1360
-			case '?':
1361
-					if (isprint(optopt))
1362
-						fprintf(stderr, "Unknown option `-%c�.\n", optopt);
1363
-					else
1364
-						fprintf(stderr, 
1365
-								"Unknown option character `\\x%x�.\n",
1366
-								optopt);
1367
-					goto error;
1368
-			case ':':
1369
-					fprintf(stderr, 
1370
-								"Option `-%c� requires an argument.\n",
1371
-								optopt);
1372
-					goto error;
1360
+			case 's':
1361
+				#ifdef STATS
1362
+					stat_file=optarg;
1363
+				#endif
1364
+					break;
1373 1365
 			default:
1374
-					abort();
1375
-		}
1376
-	}
1377
-	
1378
-	/* fill missing arguments with the default values*/
1379
-	if (cfg_file==0) cfg_file=CFG_FILE;
1380
-
1381
-	/* load config file or die */
1382
-	cfg_stream=fopen (cfg_file, "r");
1383
-	if (cfg_stream==0){
1384
-		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
1385
-				strerror(errno));
1386
-		goto error;
1387
-	}
1388
-
1389
-	/* seed the prng */
1390
-	/* try to use /dev/urandom if possible */
1391
-	seed=0;
1392
-	if ((rfd=open("/dev/urandom", O_RDONLY))!=-1){
1393
-try_again:
1394
-		if (read(rfd, (void*)&seed, sizeof(seed))==-1){
1395
-			if (errno==EINTR) goto try_again; /* interrupted by signal */
1396
-			LOG(L_WARN, "WARNING: could not read from /dev/urandom (%d)\n",
1397
-						errno);
1366
+					break;
1398 1367
 		}
1399
-		DBG("read %u from /dev/urandom\n", seed);
1400
-			close(rfd);
1401
-	}else{
1402
-		LOG(L_WARN, "WARNING: could not open /dev/urandom (%d)\n", errno);
1403 1368
 	}
1404
-	seed+=getpid()+time(0);
1405
-	DBG("seeding PRNG with %u\n", seed);
1406
-	srand(seed);
1407
-	DBG("test random number %u\n", rand());
1408
-	
1409
-	/*register builtin  modules*/
1410
-	register_builtin_modules();
1411 1369
 
1412
-	yyin=cfg_stream;
1413
-	if ((yyparse()!=0)||(cfg_errors)){
1414
-		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
1415
-		goto error;
1416
-	}
1417
-		
1418
-	print_rl();
1419
-	
1420 1370
 	/* init the resolver, before fixing the config */
1421 1371
 	resolv_init();
1422 1372
 	/* fix parameters */
... ...
@@ -1424,17 +1467,17 @@ try_again:
1424 1424
 #ifdef USE_TLS
1425 1425
 	if (tls_port_no<=0) tls_port_no=SIPS_PORT;
1426 1426
 #endif
1427
-	
1428
-	
1427
+
1428
+
1429 1429
 	if (children_no<=0) children_no=CHILD_NO;
1430 1430
 #ifdef USE_TCP
1431 1431
 	if (!tcp_disable){
1432 1432
 		if (tcp_children_no<=0) tcp_children_no=children_no;
1433 1433
 	}
1434 1434
 #endif
1435
-	
1435
+
1436 1436
 	if (working_dir==0) working_dir="/";
1437
-	
1437
+
1438 1438
 	/* get uid/gid */
1439 1439
 	if (user){
1440 1440
 		if (user2uid(&uid, &gid, user)<0){
... ...
@@ -1459,11 +1502,11 @@ try_again:
1459 1459
 	/*print_aliases();*/
1460 1460
 	print_aliases();
1461 1461
 	printf("\n");
1462
-	
1462
+
1463 1463
 	if (dont_fork){
1464
-		fprintf(stderr, "WARNING: no fork mode %s\n", 
1464
+		fprintf(stderr, "WARNING: no fork mode %s\n",
1465 1465
 				(udp_listen)?(
1466
-				(udp_listen->next)?" and more than one listen address found"
1466
+				(udp_listen->next)?"and more than one listen address found "
1467 1467
 				"(will use only the the first one)":""
1468 1468
 				):"and no udp listen address found" );
1469 1469
 	}
... ...
@@ -1474,7 +1517,7 @@ try_again:
1474 1474
 
1475 1475
 
1476 1476
 	/*init shm mallocs
1477
-	 *  this must be here 
1477
+	 *  this must be here
1478 1478
 	 *     -to allow setting shm mem size from the command line
1479 1479
 	 *       => if shm_mem should be settable from the cfg file move
1480 1480
 	 *       everything after
... ...
@@ -1489,7 +1532,7 @@ try_again:
1489 1489
 		LOG(L_CRIT, "could not initialize timer, exiting...\n");
1490 1490
 		goto error;
1491 1491
 	}
1492
-	
1492
+
1493 1493
 	if (init_avps()<0) goto error;
1494 1494
 	if (rpc_init_time() < 0) goto error;
1495 1495
 
... ...
@@ -1523,22 +1566,22 @@ try_again:
1523 1523
 	if (disable_core_dump) set_core_dump(0, 0);
1524 1524
 	else set_core_dump(1, shm_mem_size+PKG_MEM_POOL_SIZE+4*1024*1024);
1525 1525
 	if (open_files_limit>0){
1526
-		if(increase_open_fds(open_files_limit)<0){ 
1526
+		if(increase_open_fds(open_files_limit)<0){
1527 1527
 			fprintf(stderr, "ERROR: error could not increase file limits\n");
1528 1528
 			goto error;
1529 1529
 		}
1530 1530
 	}
1531
-	     /* Calculate initial process count, mod_init functions called 
1531
+	     /* Calculate initial process count, mod_init functions called
1532 1532
 	      * below can add to it
1533 1533
 	      */
1534
-	process_count = calc_proc_no(); 
1534
+	process_count = calc_proc_no();
1535 1535
 	if (init_modules() != 0) {
1536 1536
 		fprintf(stderr, "ERROR: error while initializing modules\n");
1537 1537
 		goto error;
1538 1538
 	}
1539 1539
 
1540
-	     /* The total number of processes is know now, note that no 
1541
-	      * function being called before this point may rely on the 
1540
+	     /* The total number of processes is know now, note that no
1541
+	      * function being called before this point may rely on the
1542 1542
 	      * number of processes !
1543 1543
 	      */
1544 1544
 	DBG("Expect %d SER processes in your process list\n", process_count);
... ...
@@ -1565,7 +1608,7 @@ try_again:
1565 1565
 #ifdef STATS
1566 1566
 	if (init_stats(  dont_fork ? 1 : children_no  )==-1) goto error;
1567 1567
 #endif
1568
-	
1568
+
1569 1569
 	ret=main_loop();
1570 1570
 	/*kill everything*/
1571 1571
 	kill_all_children(SIGTERM);