log_d("debugging turned on");
log_d("debugging level set to %d", debug);
void httpd_main(void){	struct server *s;	struct connection *cn;	int error;	int rv;	int n;	short r;	current_time = startuptime = time(0);	error = 0;	log_d("*** %s starting", server_version);	while (gotsigterm == 0) {		if (gotsighup) {			gotsighup = 0;			init_logs();			log_d("logs reopened");		}		if (gotsigusr1) {			gotsigusr1 = 0;			nuke_connections();			log_d("connections closed");		}		if (gotsigusr2) {			gotsigusr2 = 0;			nuke_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 (s->fd != -1) {				pollfds[n].events = POLLIN;				pollfds[n].fd = s->fd;				s->pollno = n++;			}			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;		}		rv = poll(pollfds, n, INFTIM);		current_time = time(0);		if (rv == -1) {			if (errno != EINTR) {				lerror("poll");				if (error++) {					log_d("whoops");					break;				}			}		} else {			error = 0;			if (rv) {				s = servers;				while (s) {					if (s->fd != -1) {						if (pollfds[s->pollno].revents & POLLIN)							accept_connection(s);					}					s = s->next;				}				cn = connections;				while (cn) {					if (cn->state == HC_ACTIVE) {						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");}