if (debug) log_d("httpd_main: starting poll, n=%d, t=%d", n, t);
void httpd_main(void){	struct server *s;	struct connection *cn;	int rv;	int n, t;	short r;	time_t hours;	int accepting;	time_t last_time;	accepting = 1;	last_time = current_time = startuptime = time(0);	hours = current_time / 3600;	log_d("*** %s starting", server_version);	while (gotsigterm == 0) {		if (gotsighup) {			gotsighup = 0;			init_logs();			if (debug)				log_d("logs reopened");		}		if (gotsigusr1) {			gotsigusr1 = 0;			close_connections();			log_d("connections closed");		}		if (gotsigusr2) {			gotsigusr2 = 0;			close_servers();			log_d("servers closed");		}		if (gotsigchld) {			gotsigchld = 0;			reap_children();		}		if (gotsigquit) {			gotsigquit = 0;			debug = debug == 0;			if (debug)				log_d("debugging turned on");			else				log_d("debugging turned off");		}		n = 0;		s = servers;		while (s) {			if (accepting && s->fd != -1) {				pollfds[n].events = POLLIN;				pollfds[n].fd = s->fd;				s->pollno = n++;			} else				s->pollno = -1;			s = s->next;		}		cn = connections;		while (cn) {			if (cn->state == HC_ACTIVE) {				switch (cn->action) {				case HC_WAITING:				case HC_READING:					pollfds[n].events = POLLIN;					break;				default:					pollfds[n].events = POLLOUT;					break;				}				pollfds[n].fd = cn->fd;				cn->pollno = n++;			} else				cn->pollno = -1;			cn = cn->next;		}		if (n == 0) {			log_d("no more sockets to poll from");			break;		}		t = accepting ? (nconnections ? 60000 : INFTIM) : 1000;		if (debug)			log_d("httpd_main: starting poll, n=%d, t=%d", n, t);		rv = poll(pollfds, n, t);		current_time = time(0);		if (rv == -1) {			if (errno != EINTR) {				lerror("poll");				break;			} else				continue;		}		if (current_time != last_time) {			if (accepting == 0)				accepting = 1;			last_time = current_time;			if (current_time / 3600 != hours) {				hours = current_time / 3600;				init_logs();				if (debug)					log_d("logs rotated");			}		}		if (rv) {			s = servers;			while (s) {				if (s->pollno != -1)					if (pollfds[s->pollno].revents & POLLIN)						if (accept_connection(s) == -1)							accepting = 0;				s = s->next;			}			cn = connections;			while (cn) {				if (cn->pollno != -1) {					r = pollfds[cn->pollno].revents;					if (r & POLLIN)						read_connection(cn);					else if (r & POLLOUT)						write_connection(cn);					else if (r) {						log_d("poll: unexpected event %hd", r);						cn->action = HC_CLOSING;					}				}				cn = cn->next;			}		}		cleanup_connections();	}	log_d("*** shutting down");}