diff --git a/src/modules/Pipe/pipe.c b/src/modules/Pipe/pipe.c index e5546bbdfe35e0f224b686ec803536d4deea7109..085005c97384d36ca930f0bb7dbced40d4406b91 100644 --- a/src/modules/Pipe/pipe.c +++ b/src/modules/Pipe/pipe.c @@ -1,4 +1,4 @@ -#include "config.h" +#include <config.h> #include "machine.h" #include <sys/types.h> @@ -22,9 +22,8 @@ #include <fcntl.h> #include "global.h" -RCSID("$Id: pipe.c,v 1.14 1997/10/10 18:59:47 grubba Exp $"); +RCSID("$Id: pipe.c,v 1.11 1997/12/08 15:00:00 grubba Exp $"); -#include "threads.h" #include "stralloc.h" #include "pike_macros.h" #include "object.h" @@ -57,7 +56,7 @@ RCSID("$Id: pipe.c,v 1.14 1997/10/10 18:59:47 grubba Exp $"); # define MAP_FILE 0 #endif -#define READ_BUFFER_SIZE 65536 +#define READ_BUFFER_SIZE 32768 #define MAX_BYTES_IN_BUFFER 65536 /* @@ -145,6 +144,8 @@ static int offset_output_write_callback; static int offset_output_close_callback; static int mmapped, nobjects, nstrings, noutputs, ninputs, nbuffers, sbuffers; +static char static_buffer[READ_BUFFER_SIZE]; + void close_and_free_everything(struct object *o,struct pipe *); static INLINE void output_finish(struct object *obj); static INLINE void output_try_write_some(struct object *obj); @@ -374,45 +375,38 @@ static INLINE struct pike_string* gimme_some_data(unsigned long pos) { struct buffer *b; long len; - struct pipe *this = THIS; /* We have a file cache, read from it */ - if (this->fd!=-1) + if (THIS->fd!=-1) { - char buffer[READ_BUFFER_SIZE]; - - if (this->pos<=pos) return NULL; /* no data */ - len=this->pos-pos; + if (THIS->pos<=pos) return NULL; /* no data */ + len=THIS->pos-pos; if (len>READ_BUFFER_SIZE) len=READ_BUFFER_SIZE; - THREADS_ALLOW(); - lseek(this->fd, pos, 0); /* SEEK_SET */ - THREADS_DISALLOW(); + lseek(THIS->fd,pos,0); /* SEEK_SET */ do { - THREADS_ALLOW(); - len = read(this->fd, buffer, len); - THREADS_DISALLOW(); + len = read(THIS->fd,static_buffer,len); if (len < 0) { if (errno != EINTR) { return(NULL); } } } while(len < 0); - return make_shared_binary_string(buffer,len); + return make_shared_binary_string(static_buffer,len); } - if (pos<this->pos) + if (pos<THIS->pos) return make_shared_string("buffer underflow"); /* shit */ /* We want something in the next buffer */ - while (this->firstbuffer && pos>=this->pos+this->firstbuffer->s->len) + while (THIS->firstbuffer && pos>=THIS->pos+THIS->firstbuffer->s->len) { /* Free the first buffer, and update THIS->pos */ - b=this->firstbuffer; - this->pos+=b->s->len; - this->bytes_in_buffer-=b->s->len; - this->firstbuffer=b->next; + b=THIS->firstbuffer; + THIS->pos+=b->s->len; + THIS->bytes_in_buffer-=b->s->len; + THIS->firstbuffer=b->next; if (!b->next) - this->lastbuffer=NULL; + THIS->lastbuffer=NULL; sbuffers-=b->s->len; nbuffers--; free_string(b->s); @@ -421,48 +415,41 @@ static INLINE struct pike_string* gimme_some_data(unsigned long pos) /* Wake up first input if it was sleeping and we * have room for more in the buffer. */ - if (this->sleeping && - this->firstinput && - this->bytes_in_buffer<MAX_BYTES_IN_BUFFER) + if (THIS->sleeping && + THIS->firstinput && + THIS->bytes_in_buffer<MAX_BYTES_IN_BUFFER) { - this->sleeping=0; + THIS->sleeping=0; push_callback(offset_input_read_callback); push_int(0); push_callback(offset_input_close_callback); - apply(this->firstinput->u.obj, "set_nonblocking", 3); + apply(THIS->firstinput->u.obj, "set_nonblocking", 3); pop_stack(); } } - while (!this->firstbuffer) + while (!THIS->firstbuffer) { - if (this->firstinput) + if (THIS->firstinput) { #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) - if (this->firstinput->type==I_MMAP) + if (THIS->firstinput->type==I_MMAP) { - char *src; - struct pike_string *tmp; - - if (pos >= this->firstinput->len + this->pos) /* end of mmap */ + if (pos >= THIS->firstinput->len + THIS->pos) /* end of mmap */ { - this->pos += this->firstinput->len; + THIS->pos+=THIS->firstinput->len; input_finish(); continue; } - len = this->firstinput->len + this->pos - pos; - if (len > READ_BUFFER_SIZE) len=READ_BUFFER_SIZE; - tmp = begin_shared_string( len ); - src = this->firstinput->u.mmap + pos - this->pos; -/* This thread_allow/deny is at the cost of one extra memory copy */ - THREADS_ALLOW(); - MEMCPY(tmp->str, src, len); - THREADS_DISALLOW(); - return end_shared_string(tmp); + len=THIS->firstinput->len+THIS->pos-pos; + if (len>READ_BUFFER_SIZE) len=READ_BUFFER_SIZE; + return make_shared_binary_string(THIS->firstinput->u.mmap+ + pos-THIS->pos, + len); } else #endif - if (this->firstinput->type!=I_OBJ) + if (THIS->firstinput->type!=I_OBJ) { input_finish(); /* shouldn't be anything else ... maybe a finished object */ } @@ -470,15 +457,15 @@ static INLINE struct pike_string* gimme_some_data(unsigned long pos) return NULL; /* no data */ } - if (pos==this->pos) + if (pos==THIS->pos) { - this->firstbuffer->s->refs++; - return this->firstbuffer->s; + THIS->firstbuffer->s->refs++; + return THIS->firstbuffer->s; } - return make_shared_binary_string(this->firstbuffer->s->str+ - pos-this->pos, - this->firstbuffer->s->len- - pos+this->pos); + return make_shared_binary_string(THIS->firstbuffer->s->str+ + pos-THIS->pos, + THIS->firstbuffer->s->len- + pos+THIS->pos); } @@ -620,46 +607,12 @@ static void pipe_input(INT32 args) && ((long)(m=(char *)mmap(0,s.st_size - filep,PROT_READ, MAP_FILE|MAP_SHARED,fd,filep))!=-1)) { -#ifdef HAVE_GETEUID - int ou = 0; -#endif mmapped += s.st_size; i->type=I_MMAP; i->len=s.st_size; i->u.mmap=m; -#ifdef HAVE_MADVISE - /* Mark the pages as sequential read only access... */ - - /* NOTE: - * - * Potential race-condition with other threads - */ - -#ifdef HAVE_GETEUID - if((ou=geteuid()) && !getuid()) { -#ifdef HAVE_SETEUID - seteuid(0); -#else /* ! HAVE_SETEUID */ -#ifdef HAVE_SETREUID - setresuid(-1, 0, -1); -#endif /* HAVE_SETRESUID */ -#endif /* HAVE_SETEUID */ - } -#endif - madvise(m, s.st_size, MADV_SEQUENTIAL); -#ifdef HAVE_GETEUID - if(ou) { -#ifdef HAVE_SETEUID - seteuid(0); -#else /* ! HAVE_SETEUID */ -#ifdef HAVE_SETREUID - setresuid(-1, ou, -1); -#endif /* HAVE_SETRESUID */ -#endif /* HAVE_SETEUID */ - } -#endif -#endif + pop_n_elems(args); push_int(0); return;