rem: if (pids==0){
add: if (pt==0){
context: int main(int argc, char** argv){	FILE* cfg_stream;	struct hostent* he;	int c,r,t;	char *tmp;	char** h;	struct host_alias* a;	struct utsname myname;	char *options;	char port_no_str[MAX_PORT_LEN];	int port_no_str_len=0;	/* added by jku: add exit handler */	if (signal(SIGINT, sig_usr) == SIG_ERR ) {		DPrint("ERROR: no SIGINT signal handler can be installed\n");		goto error;	}	/* if we debug and write to a pipe, we want to exit nicely too */	if (signal(SIGPIPE, sig_usr) == SIG_ERR ) {		DPrint("ERROR: no SIGINT signal handler can be installed\n");		goto error;	}	if (signal(SIGUSR1, sig_usr)  == SIG_ERR ) {		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");		goto error;	}	if (signal(SIGCHLD , sig_usr)  == SIG_ERR ) {		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");		goto error;	}	if (signal(SIGTERM , sig_usr)  == SIG_ERR ) {		DPrint("ERROR: no SIGTERM signal handler can be installed\n");		goto error;	}	if (signal(SIGHUP , sig_usr)  == SIG_ERR ) {		DPrint("ERROR: no SIGHUP signal handler can be installed\n");		goto error;	}	if (signal(SIGUSR2 , sig_usr)  == SIG_ERR ) {		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");		goto error;	}#ifdef DBG_MSG_QA	fprintf(stderr, "WARNING: ser startup: "		"DBG_MSG_QA enabled, ser may exit abruptly\n");#endif	/* process command line (get port no, cfg. file path etc) */	opterr=0;	options=#ifdef STATS	"s:"#endif	"f:p:m:b:l:n:rRvdDEVhw:t:u:g:P:";		while((c=getopt(argc,argv,options))!=-1){		switch(c){			case 'f':					cfg_file=optarg;					break;			case 's':				#ifdef STATS					stat_file=optarg;				#endif					break;			case 'p':					port_no=strtol(optarg, &tmp, 10);					if (tmp &&(*tmp)){						fprintf(stderr, "bad port number: -p %s\n", optarg);						goto error;					}					if (sock_no>0) sock_info[sock_no-1].port_no=port_no;					break;			case 'm':					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;					if (tmp &&(*tmp)){						fprintf(stderr, "bad shmem size number: -m %s\n",										optarg);						goto error;					};					LOG(L_INFO, "ser: shared memory allocated: %d MByte\n",									shm_mem_size );					break;			case 'b':					maxbuffer=strtol(optarg, &tmp, 10);					if (tmp &&(*tmp)){						fprintf(stderr, "bad max buffer size number: -p %s\n",											optarg);						goto error;					}					break;			case 'l':					/* add a new addr. to our address list */					if (sock_no < MAX_LISTEN){						sock_info[sock_no].name.s=										(char*)malloc(strlen(optarg)+1);						if (sock_info[sock_no].name.s==0){							fprintf(stderr, "Out of memory.\n");							goto error;						}						strncpy(sock_info[sock_no].name.s, optarg,												strlen(optarg)+1);						sock_info[sock_no].name.len=strlen(optarg);						/* set default port */						sock_info[sock_no].port_no=port_no;						sock_no++;					}else{						fprintf(stderr, 									"Too many addresses (max. %d).\n",									MAX_LISTEN);						goto error;					}					break;			case 'n':					children_no=strtol(optarg, &tmp, 10);					if ((tmp==0) ||(*tmp)){						fprintf(stderr, "bad process number: -n %s\n",									optarg);						goto error;					}					break;			case 'v':					check_via=1;					break;			case 'r':					received_dns|=DO_DNS;					break;			case 'R':					received_dns|=DO_REV_DNS;			case 'd':					debug++;					break;			case 'D':					dont_fork=1;					break;			case 'E':					log_stderr=1;					break;			case 'V':					printf("version: %s\n", version);					printf("flags: %s\n", flags );					print_ct_constants();					printf("%s\n",id);					printf("%s compiled on %s with %s\n", __FILE__,							compiled, COMPILER );										exit(0);					break;			case 'h':					printf("version: %s\n", version);					printf("%s",help_msg);					exit(0);					break;			case 'w':					working_dir=optarg;					break;			case 't':					chroot_dir=optarg;					break;			case 'u':					uid=strtol(optarg, &tmp, 10);					if ((tmp==0) ||(*tmp)){						fprintf(stderr, "bad uid number: -u %s\n", optarg);						goto error;					}					/* test if string?*/					break;			case 'g':					gid=strtol(optarg, &tmp, 10);					if ((tmp==0) ||(*tmp)){						fprintf(stderr, "bad gid number: -g %s\n", optarg);						goto error;					}					break;			case 'P':					pid_file=optarg;					break;			case '?':					if (isprint(optopt))						fprintf(stderr, "Unknown option `-%c.\n", optopt);					else						fprintf(stderr, 								"Unknown option character `\\x%x.\n",								optopt);					goto error;			case ':':					fprintf(stderr, 								"Option `-%c requires an argument.\n",								optopt);					goto error;			default:					abort();		}	}		/* fill missing arguments with the default values*/	if (cfg_file==0) cfg_file=CFG_FILE;	/* load config file or die */	cfg_stream=fopen (cfg_file, "r");	if (cfg_stream==0){		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,				strerror(errno));		goto error;	}        init_hfname_parser();	init_digest_parser();	/* init hash fucntion */	if (init_hash()<0) {		LOG(L_ERR, "ERROR: init_hash failed\n");		goto error;	}	/*init mallocs (before parsing cfg !)*/	if (init_mallocs()==-1)		goto error;	/*init timer, before parsing the cfg!*/	if (init_timer()<0){		LOG(L_CRIT, "could not initialize timer, exiting...\n");		goto error;	}	/* register a diagnostic FIFO command */	if (register_core_fifo()<0) {		LOG(L_CRIT, "unable to register core FIFO commands\n");		goto error;	}	/*register builtin  modules*/	register_builtin_modules();	yyin=cfg_stream;	if ((yyparse()!=0)||(cfg_errors)){		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);		goto error;	}	print_rl();	/* fix parameters */	if (port_no<=0) port_no=SIP_PORT;		if (children_no<=0) children_no=CHILD_NO;#ifdef _OBSOLETED	else if (children_no >= MAX_PROCESSES ) {		fprintf(stderr, "ERROR: too many children processes configured;"				" maximum is %d\n",			MAX_PROCESSES-1 );		goto error;	}#endif		if (working_dir==0) working_dir="/";	if (sock_no==0) {		/* try to get all listening ipv4 interfaces */		if (add_interfaces(0, AF_INET, 0)==-1){			/* if error fall back to get hostname*/			/* get our address, only the first one */			if (uname (&myname) <0){				fprintf(stderr, "cannot determine hostname, try -l address\n");				goto error;			}			sock_info[sock_no].name.s=(char*)malloc(strlen(myname.nodename)+1);			if (sock_info[sock_no].name.s==0){				fprintf(stderr, "Out of memory.\n");				goto error;			}			sock_info[sock_no].name.len=strlen(myname.nodename);			strncpy(sock_info[sock_no].name.s, myname.nodename,					sock_info[sock_no].name.len+1);			sock_no++;		}	}	/* try to change all the interface names into addresses	 *  --ugly hack */	for (r=0; r<sock_no;){		if (add_interfaces(sock_info[r].name.s, AF_INET,					sock_info[r].port_no)!=-1){			/* success => remove current entry (shift the entire array)*/			free(sock_info[r].name.s);			memmove(&sock_info[r], &sock_info[r+1], 						(sock_no-r)*sizeof(struct socket_info));			sock_no--;			continue;		}		r++;	}	/* get ips & fill the port numbers*/	printf("Listening on \n");	for (r=0; r<sock_no;r++){		he=resolvehost(sock_info[r].name.s);		if (he==0){			DPrint("ERROR: could not resolve %s\n", sock_info[r].name.s);			goto error;		}		/* check if we got the official name */		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){			if (add_alias(sock_info[r].name.s, sock_info[r].name.len)<0){				LOG(L_ERR, "ERROR: main: add_alias failed\n");			}			/* change the oficial name */			free(sock_info[r].name.s);			sock_info[r].name.s=(char*)malloc(strlen(he->h_name)+1);			if (sock_info[r].name.s==0){				fprintf(stderr, "Out of memory.\n");				goto error;			}			sock_info[r].name.len=strlen(he->h_name);			strncpy(sock_info[r].name.s, he->h_name, sock_info[r].name.len+1);		}		/* add the aliases*/		for(h=he->h_aliases; h && *h; h++)			if (add_alias(*h, strlen(*h))<0){				LOG(L_ERR, "ERROR: main: add_alias failed\n");			}				hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 														 format*/		if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;		sock_info[r].address_str.s=(char*)malloc(strlen(tmp)+1);		if (sock_info[r].address_str.s==0){			fprintf(stderr, "Out of memory.\n");			goto error;		}		strncpy(sock_info[r].address_str.s, tmp, strlen(tmp)+1);		/* set is_ip (1 if name is an ip address, 0 otherwise) */		sock_info[r].address_str.len=strlen(tmp);		if 	(	(sock_info[r].address_str.len==sock_info[r].name.len)&&				(strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,						 sock_info[r].address_str.len)==0)			)	sock_info[r].is_ip=1;		else sock_info[r].is_ip=0;					if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;		port_no_str_len=snprintf(port_no_str, MAX_PORT_LEN, ":%d", 									(unsigned short) sock_info[r].port_no);		if (port_no_str_len<0){			fprintf(stderr, "ERROR: bad port number: %d\n", 						sock_info[r].port_no);			goto error;		}		/* on some systems snprintf returns really strange things if it does 		  not have  enough space */		port_no_str_len=				(port_no_str_len<MAX_PORT_LEN)?port_no_str_len:MAX_PORT_LEN;		sock_info[r].port_no_str.s=(char*)malloc(strlen(port_no_str)+1);		if (sock_info[r].port_no_str.s==0){			fprintf(stderr, "Out of memory.\n");			goto error;		}		strncpy(sock_info[r].port_no_str.s, port_no_str, strlen(port_no_str)+1);		sock_info[r].port_no_str.len=strlen(port_no_str);				printf("              %s [%s]:%s\n",sock_info[r].name.s,				sock_info[r].address_str.s, sock_info[r].port_no_str.s);	}	/* removing duplicate addresses*/	for (r=0; r<sock_no; r++){		for (t=r+1; t<sock_no;){			if ((sock_info[r].port_no==sock_info[t].port_no) &&				(sock_info[r].address.af==sock_info[t].address.af) &&				(memcmp(sock_info[r].address.u.addr, 						sock_info[t].address.u.addr,						sock_info[r].address.len)  == 0)				){				printf("removing duplicate (%d) %s [%s] == (%d) %s [%s]\n",						r, sock_info[r].name.s, sock_info[r].address_str.s,						t, sock_info[t].name.s, sock_info[t].address_str.s);								/* add the name to the alias list*/				if ((!sock_info[t].is_ip) && (						(sock_info[t].name.len!=sock_info[r].name.len)||						(strncmp(sock_info[t].name.s, sock_info[r].name.s,								 sock_info[r].name.len)!=0))					)					add_alias(sock_info[t].name.s, sock_info[t].name.len);										/* free space*/				free(sock_info[t].name.s);				free(sock_info[t].address_str.s);				free(sock_info[t].port_no_str.s);				/* shift the array*/				memmove(&sock_info[t], &sock_info[t+1], 							(sock_no-t)*sizeof(struct socket_info));				sock_no--;				continue;			}			t++;		}	}	/* print all the listen addresses */	printf("Listening on \n");	for (r=0; r<sock_no; r++)		printf("              %s [%s]:%s\n",sock_info[r].name.s,				sock_info[r].address_str.s, sock_info[r].port_no_str.s);	printf("Aliases: ");	for(a=aliases; a; a=a->next) printf("%.*s ", a->alias.len, a->alias.s);	printf("\n");	if (sock_no==0){		fprintf(stderr, "ERROR: no listening sockets");		goto error;	}	if (dont_fork){		fprintf(stderr, "WARNING: no fork mode %s\n", 				(sock_no>1)?" and more than one listen address found (will use only the"				" the first one)":"");	}		/*alloc pids*/#ifdef SHM_MEM	pids=shm_malloc(sizeof(int)*(children_no*sock_no+1/*main*/+1/*timer */+1/*fifo*/));#else	pids=malloc(sizeof(int)*(children_no*sock_no+1+1+1));#endif	if (pids==0){		fprintf(stderr, "ERROR: out  of memory\n");		goto error;	}	memset(pids, 0, sizeof(int)*(children_no+1));		/* init_daemon? */	if (!dont_fork){		if ( daemonize(argv[0]) <0 ) goto error;	}	if (init_modules() != 0) {		fprintf(stderr, "ERROR: error while initializing modules\n");		goto error;	}	/* fix routing lists */	if ( (r=fix_rls())!=0){		fprintf(stderr, "ERROR: error %x while trying to fix configuration\n",						r);		goto error;	};#ifdef STATS	if (init_stats(  dont_fork ? 1 : children_no  )==-1) goto error;#endif		return main_loop();error:	return -1;}