log_d("pipe_run: too many headers");
log_d("pipe_run: buffer full");
static void pipe_run(struct pipe_params *p){	short revents;	char c;	ssize_t r;	size_t room;	size_t bytestocopy;	int convert_result;	size_t bytestoread;	char chunkbuf[16];	size_t chunkheaderlen;	if (p->cpollno != -1) {		revents = pollfds[p->cpollno].revents;		if (revents & ~(POLLIN | POLLOUT)) {			log_d("pipe_run: revents=%hd", revents);			p->error_condition = STUB_ERROR_CLIENT;			return;		}		if (revents & POLLIN) {			bytestoread = p->isize - p->ibp;			if (bytestoread > p->imax)				bytestoread = p->imax;			if (bytestoread == 0) {				log_d("pipe_run: nothing to read from client!");				p->error_condition = STUB_ERROR_CLIENT;				return;			}			r = read(p->cfd, p->ibuf + p->ibp, bytestoread);			switch (r) {			case -1:				if (errno == EAGAIN)					break;				if (errno != ECONNRESET && errno != EPIPE)					lerror("pipe_run: error reading from client");				p->error_condition = STUB_ERROR_CLIENT;				return;			case 0:				log_d("pipe_run: client went away while posting data");				p->error_condition = STUB_ERROR_CLIENT;				return;			default:				p->t = current_time;				p->cn->nread += r;				p->ibp += r;				p->imax -= r;				break;			}		}		if (revents & POLLOUT) {			r = write(p->cfd, p->obuf + p->obp, p->otop - p->obp);			switch (r) {			case -1:				if (errno == EAGAIN)					break;				if (errno != ECONNRESET && errno != EPIPE)					lerror("pipe_run: error writing to client");				p->error_condition = STUB_ERROR_CLIENT;				return;			default:				p->t = current_time;				p->cn->nwritten += r;				p->obp += r;				break;			}		}	}	if (p->ppollno != -1) {		revents = pollfds[p->ppollno].revents;		if (revents & ~(POLLIN | POLLOUT)) {			log_d("pipe_run: revents=%hd", revents);			p->error_condition = STUB_ERROR_PIPE;			return;		}		if (revents & POLLIN) {			bytestoread = p->psize - p->ipp;			if (p->haslen && bytestoread > p->pmax)				bytestoread = p->pmax;			if (bytestoread == 0) {				log_d("pipe_run: nothing to read from pipe");				p->error_condition = STUB_ERROR_PIPE;				return;			}			r = read(p->pfd, p->pbuf + p->ipp, bytestoread);			switch (r) {			case -1:				if (errno == EAGAIN)					break;				lerror("pipe_run: error reading from script");				p->error_condition = STUB_ERROR_PIPE;				return;			case 0:				if (p->state != 2) {					log_d("pipe_run: premature end of script headers");					p->error_condition = STUB_ERROR_RESTART;					return;				}				if (p->haslen) {					log_d("pipe_run: script went away");					p->error_condition = STUB_ERROR_PIPE;					return;				}				p->t = current_time;				p->pstate = 2;				break;			default:				p->t = current_time;				p->ipp += r;				if (p->haslen)					p->pmax -= r;				break;			}		}		if (revents & POLLOUT) {			r = write(p->pfd, p->ibuf + p->opp, p->ibp - p->opp);			switch (r) {			case -1:				if (errno == EAGAIN)					break;				lerror("pipe_run: error writing to script");				p->error_condition = STUB_ERROR_PIPE;				return;			default:				p->t = current_time;				p->opp += r;				break;			}		}	}	if (p->opp && p->opp == p->ibp)		p->opp = p->ibp = 0;	if (p->obp && p->obp == p->otop)		p->obp = p->otop = 0;	if (p->ipp && p->state != 2) {		while (p->pstart < p->ipp && p->state != 2) {			c = p->pbuf[p->pstart++];			switch (p->state) {			case 0:				if (c == '\n')					p->state = 1;				break;			case 1:				switch (c) {				case '\r':					break;				case '\n':					p->state = 2;					break;				default:					p->state = 0;					break;				}				break;			}		}		if (p->state == 2) {			convert_result = convert_cgi_headers(p, &p->cn->r->status);			if (convert_result == -1) {				log_d("pipe_run: problem in convert_cgi_headers");				p->error_condition = STUB_ERROR_RESTART;				return;			}			if (p->haslen && p->pstart < p->ipp) {				if (p->ipp > p->pstart + p->pmax) {					log_d("extra garbage from script ignored");					p->ipp = p->pstart + p->pmax;					p->pmax = 0;				} else					p->pmax -= p->ipp - p->pstart;			}		} else if (p->pstart == p->psize) {			log_d("pipe_run: too many headers");			p->error_condition = STUB_ERROR_RESTART;			return;		}	}	if (p->state == 2 && p->pstart < p->ipp) {		if (p->nocontent)			p->pstart = p->ipp = 0;		else {			room = p->osize - p->otop;			bytestocopy = p->ipp - p->pstart;			if (bytestocopy > room)				bytestocopy = room;			if (bytestocopy && p->chunkit) {				chunkheaderlen = sprintf(chunkbuf, "%lx\r\n", (unsigned long) bytestocopy);				if (chunkheaderlen + 2 >= room)					bytestocopy = 0;				else {					if (bytestocopy + chunkheaderlen + 2 > room) {						bytestocopy -= chunkheaderlen + 2;						chunkheaderlen = sprintf(chunkbuf, "%lx\r\n", (unsigned long) bytestocopy);					}					memcpy(p->obuf + p->otop, chunkbuf, chunkheaderlen);					p->otop += chunkheaderlen;				}			}			if (bytestocopy) {				memcpy(p->obuf + p->otop, p->pbuf + p->pstart, bytestocopy);				p->otop += bytestocopy;				p->pstart += bytestocopy;				if (p->pstart == p->ipp)					p->pstart = p->ipp = 0;				if (p->chunkit) {					memcpy(p->obuf + p->otop, "\r\n", 2);					p->otop += 2;				}			}		}	}	if (p->pstate == 2 && p->chunkit && p->nocontent == 0) {		if (p->osize - p->otop >= 5) {			memcpy(p->obuf + p->otop, "0\r\n\r\n", 5);			p->otop += 5;			p->pstate = 3;		}	}}