supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* runit: buffer_feed()
@ 2009-01-23 13:06 Tomas Carnecky
  2009-01-23 14:30 ` Charlie Brady
  0 siblings, 1 reply; 4+ messages in thread
From: Tomas Carnecky @ 2009-01-23 13:06 UTC (permalink / raw)
  To: supervision

I'm looking at the buffer_feed() function in runit and I can't make 
sense of it. I'm in the process of replacing all byte_* functions with 
standard memcpy/memcmp etc, but I just don't see what this byte_copyr() 
is supposed to do:

int buffer_feed(buffer *s)
{
   int r;

   if (s->p) return s->p;
   r = oneread(s->op,s->fd,s->x,s->n);
   if (r <= 0) return r;
   s->p = r;
   s->n -= r;
   if (s->n > 0) byte_copyr(s->x + s->n,r,s->x);
   return r;
}

byte_copyr() copies backwards, so you're reading/accessing bytes 
_before_ s->x. Shouldn't that cause a SIGSEGV?
Also, what is ->p and ->n? ->n seems to be the offset into the ->s char 
array, ->p the number of bytes currently in the buffer. It looks that 
way if I look at buffer_peek(), but ->n is initialized to 'len', which 
means that buffer_peek() just after the buffer is initialized returns a 
pointer beyond the end of the buffer.. ? Also, ->n is decreased after 
data is read into the buffer (using oneread). That doesn't make sense. 
It's all very confusing.

Can sombody please explain how the code is supposed to work?

thanks
tom



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-01-23 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-23 13:06 runit: buffer_feed() Tomas Carnecky
2009-01-23 14:30 ` Charlie Brady
2009-01-23 14:57   ` Tomas Carnecky
2009-01-23 17:06     ` Laurent Bercot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).