only get a buffer if we really need it (fixed #280)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@723 152afb58-edef-0310-8abb-c4023f1b3aa9svn/tags/lighttpd-1.4.6
parent
09a26806f4
commit
f5ca9798df
|
@ -722,15 +722,31 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
|
|||
if (-1 == waitpid(pid, &status, 0)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "waitpid failed:", strerror(errno));
|
||||
} else if (WIFEXITED(status)) {
|
||||
|
||||
int toread;
|
||||
/* read everything from client and paste it into the output */
|
||||
|
||||
for (b = chunkqueue_get_append_buffer(con->write_queue), buffer_prepare_copy(b, 4096);
|
||||
(r = read(from_exec_fds[0], b->ptr, b->size - 1)) > 0;
|
||||
b = chunkqueue_get_append_buffer(con->write_queue), buffer_prepare_copy(b, 4096)) {
|
||||
|
||||
b->used = r;
|
||||
b->ptr[b->used++] = '\0';
|
||||
|
||||
while(1) {
|
||||
if (ioctl(from_exec_fds[0], FIONREAD, &toread)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s",
|
||||
"unexpected end-of-file (perhaps the ssi-exec process died)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (toread > 0) {
|
||||
b = chunkqueue_get_append_buffer(con->write_queue);
|
||||
|
||||
buffer_prepare_copy(b, toread + 1);
|
||||
|
||||
if ((r = read(from_exec_fds[0], b->ptr, b->size - 1)) < 0) {
|
||||
/* read failed */
|
||||
break;
|
||||
} else {
|
||||
b->used = r;
|
||||
b->ptr[b->used++] = '\0';
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s", "process exited abnormally");
|
||||
|
|
Loading…
Reference in New Issue