rem: if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
add: if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
context: int main_loop(){	int r, i;	pid_t pid;#ifdef USE_TCP	int sockfd[2];#endif#ifdef WITH_SNMP_MOD	int (*snmp_start)();	/* initialize snmp module */	snmp_start = (int(*)())find_export("snmp_start", 0);	if(snmp_start)		if(snmp_start() == -1)			LOG(L_ERR, "ERROR: Couldn't start snmp agent\n");#endif			/* one "main" process and n children handling i/o */	if (dont_fork){#ifdef STATS		setstats( 0 );#endif		/* only one address, we ignore all the others */		if (udp_init(&sock_info[0])==-1) goto error;		bind_address=&sock_info[0];		bind_idx=0;		if (sock_no>1){			LOG(L_WARN, "WARNING: using only the first listen address"						" (no fork)\n");		}		/* process_no now initialized to zero -- increase from now on		   as new processes are forked (while skipping 0 reserved for main 		*/		/* we need another process to act as the timer*/#ifndef USE_TCP		/* if we are using tcp we always need a timer process,		 * we cannot count on select timeout to measure time		 * (it works only on linux)		 */		if (timer_list)#endif		{				process_no++;				if ((pid=fork())<0){					LOG(L_CRIT,  "ERROR: main_loop: Cannot fork\n");					goto error;				}								if (pid==0){					/* child */					/* timer!*/					/* process_bit = 0; */					for(;;){						sleep(TIMER_TICK);						timer_ticker();					}				}else{						pt[process_no].pid=pid; /*should be shared mem anway*/						strncpy(pt[process_no].desc, "timer", MAX_PT_DESC );				}		}		/* if configured to do so, start a server for accepting FIFO commands */		if (open_fifo_server()<0) {			LOG(L_ERR, "opening fifo server failed\n");			goto error;		}		/* main process, receive loop */		process_no=0; /*main process number*/		pt[process_no].pid=getpid();		snprintf(pt[process_no].desc, MAX_PT_DESC, 			"stand-alone receiver @ %s:%s", 			 bind_address->name.s, bind_address->port_no_str.s );						     /* We will call child_init even if we		      * do not fork		      */		if (init_child(0) < 0) {			LOG(L_ERR, "init_child failed\n");			goto error;		}		is_main=1; /* hack 42: call init_child with is_main=0 in case					 some modules wants to fork a child */				return udp_rcv_loop();	}else{		/* process_no now initialized to zero -- increase from now on		   as new processes are forked (while skipping 0 reserved for main )		*/		for(r=0;r<sock_no;r++){			/* create the listening socket (for each address)*/			/* udp */			if (udp_init(&sock_info[r])==-1) goto error;			/* get first ipv4/ipv6 socket*/			if ((sock_info[r].address.af==AF_INET)&&					((sendipv4==0)||(sendipv4->is_lo)))				sendipv4=&sock_info[r];	#ifdef USE_IPV6			if((sendipv6==0)&&(sock_info[r].address.af==AF_INET6))				sendipv6=&sock_info[r];	#endif#ifdef USE_TCP			tcp_info[r]=sock_info[r]; /* copy the sockets */			/* same thing for tcp */			if (tcp_init(&tcp_info[r])==-1)  goto error;			/* get first ipv4/ipv6 socket*/			if ((tcp_info[r].address.af==AF_INET)&&					((sendipv4_tcp==0)||(sendipv4_tcp->is_lo)))				sendipv4_tcp=&tcp_info[r];	#ifdef USE_IPV6			if((sendipv6_tcp==0)&&(tcp_info[r].address.af==AF_INET6))				sendipv6_tcp=&tcp_info[r];	#endif#endif			/* all procs should have access to all the sockets (for sending)			 * so we open all first*/		}		for(r=0; r<sock_no;r++){			for(i=0;i<children_no;i++){				process_no++;#ifdef USE_TCP		 		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){					LOG(L_ERR, "ERROR: main_loop: socketpair failed: %s\n",						strerror(errno));					goto error;				}#endif				if ((pid=fork())<0){					LOG(L_CRIT,  "main_loop: Cannot fork\n");					goto error;				}else if (pid==0){					     /* child */#ifdef USE_TCP					close(sockfd[0]);					unix_tcp_sock=sockfd[1];#endif					bind_address=&sock_info[r]; /* shortcut */					bind_idx=r;					if (init_child(i) < 0) {						LOG(L_ERR, "init_child failed\n");						goto error;					}#ifdef STATS					setstats( i+r*children_no );#endif					return udp_rcv_loop();				}else{						pt[process_no].pid=pid; /*should be in shared mem.*/						snprintf(pt[process_no].desc, MAX_PT_DESC,							"receiver child=%d sock=%d @ %s:%s", i, r, 								sock_info[r].name.s, sock_info[r].port_no_str.s );#ifdef USE_TCP						close(sockfd[1]);						pt[process_no].unix_sock=sockfd[0];						pt[process_no].idx=-1; /* this is not "tcp" process*/#endif				}			}			/*parent*/			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/		}	}	/*this is the main process*/	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */	bind_idx=0;					/* if it does it will use the first address */		/* if configured to do so, start a server for accepting FIFO commands */	if (open_fifo_server()<0) {		LOG(L_ERR, "opening fifo server failed\n");		goto error;	}#ifndef USE_TCP	/* if we are using tcp we always need the timer */	if (timer_list)#endif	{#ifdef USE_TCP 		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){			LOG(L_ERR, "ERROR: main_loop: socketpair failed: %s\n",				strerror(errno));			goto error;		}#endif		/* fork again for the attendant process*/		process_no++;		if ((pid=fork())<0){			LOG(L_CRIT, "main_loop: cannot fork timer process\n");			goto error;		}else if (pid==0){			/* child */			/* is_main=0; */#ifdef USE_TCP			close(sockfd[0]);			unix_tcp_sock=sockfd[1];#endif			for(;;){				/* debug:  instead of doing something usefull */				/* (placeholder for timers, etc.) */				sleep(TIMER_TICK);				/* if we received a signal => TIMER_TICK may have not elapsed*/				timer_ticker();			}		}else{			pt[process_no].pid=pid;			strncpy(pt[process_no].desc, "timer", MAX_PT_DESC );#ifdef USE_TCP						close(sockfd[1]);						pt[process_no].unix_sock=sockfd[0];						pt[process_no].idx=-1; /* this is not a "tcp" process*/#endif		}	}#ifdef USE_TCP			/* start tcp receivers */		if (tcp_init_children()<0) goto error;			/* start tcp master proc */		process_no++;		if ((pid=fork())<0){			LOG(L_CRIT, "main_loop: cannot fork tcp main process\n");			goto error;		}else if (pid==0){			/* child */			/* is_main=0; */			tcp_main_loop();		}else{			pt[process_no].pid=pid;			strncpy(pt[process_no].desc, "tcp main process", MAX_PT_DESC );			pt[process_no].unix_sock=-1;			pt[process_no].idx=-1; /* this is not a "tcp" process*/			unix_tcp_sock=-1;		}#endif	/* main */	pt[0].pid=getpid();	strncpy(pt[0].desc, "attendant", MAX_PT_DESC );#ifdef USE_TCP	pt[process_no].unix_sock=-1;	pt[process_no].idx=-1; /* this is not a "tcp" process*/	unix_tcp_sock=-1;#endif	/*DEBUG- remove it*/#ifdef DEBUG	printf("\n% 3d processes, % 3d children * % 3d listening addresses + main"			" + fifo %s\n", process_no+1, children_no, sock_no,			(timer_list)?"+ timer":"");	for (r=0; r<=process_no; r++){		printf("% 3d   % 5d\n", r, pt[r].pid);	}#endif	process_no=0; 	/* process_bit = 0; */	is_main=1;		for(;;){			pause();			handle_sigs();	}			/*return 0; */ error:	return -1;}