if (gotsigquit) { gotsigquit = 0; debug = debug == 0; if (debug) log_d("debugging turned on"); else log_d("debugging turned off"); }
void httpd_main(void){	struct server *s;	struct connection *cn;	int first;	int error;	int rv;	fd_set rfds, wfds;	int m;	first = 1;	error = 0;	log_file = -1;	error_file = -1;	while (gotsigterm == 0) {		if (gotsighup) {			gotsighup = 0;			if (init_logs() == -1)				break;			if (first) {				first = 0;				log_d("*** %s starting", server_version);			}			else				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 (gotsigwinch) {			gotsigwinch = 0;			dump();		}		if (gotsigchld)			reap_children();		m = -1;		FD_ZERO(&rfds);		FD_ZERO(&wfds);		s = servers;		while (s) {			if (s->fd != -1) {				FD_SET(s->fd, &rfds);				if (s->fd > m)					m = s->fd;			}			s = s->next;		}		cn = connections;		while (cn) {			if (cn->state == HC_ACTIVE) {				switch (cn->action) {				case HC_WAITING:				case HC_READING:					FD_SET(cn->fd, &rfds);					break;				default:					FD_SET(cn->fd, &wfds);					break;				}				if (cn->fd > m)					m = cn->fd;			}			cn = cn->next;		}		if (m == -1) {			log_d("no more sockets to select from");			break;		}		if (debug)			log_d("httpd_main: select(%d) ...", m + 1);		rv = select(m + 1, &rfds, &wfds, 0, 0);		current_time = time(0);		if (debug)			log_d("httpd_main: select() = %d", rv);		if (rv == -1) {			if (errno != EINTR) {				lerror("select");				if (error++) {					log_d("whoops");					break;				}			}		} else {			error = 0;			if (rv) {				s = servers;				while (s) {					if (s->fd != -1) {						if (FD_ISSET(s->fd, &rfds))							accept_connection(s);					}					s = s->next;				}				cn = connections;				while (cn) {					if (cn->state == HC_ACTIVE) {						if (FD_ISSET(cn->fd, &rfds))							read_connection(cn);						else if (FD_ISSET(cn->fd, &wfds))							write_connection(cn);					}					cn = cn->next;				}			}			cleanup_connections();		}	}	dump();	log_d("*** shutting down", my_pid);}