[PATCH] Fix syslogd circular log buffer: head pointer not moved forward

Denys Vlasenko vda.linux at googlemail.com
Sun Aug 12 21:20:44 UTC 2007


On Thursday 09 August 2007 21:04, Jari Takkala wrote:
> Hello,
>
> The following patch fixes the circular log buffer in syslogd. Currently the
> head pointer is never moved forward. The 'logread' command will always read
> from the beginning of the buffer, even if the log buffer wraps.
>
> The head pointer is not moved forward because it is 0 by default, so the
> comparison (old_tail < shbuf->head) never evaluates to true.
>
> I have only been able to test this patch on Busybox 1.4.2. I've included a
> patch for 1.6.0 as well, if someone would please test and commit it. Thank
> you!
>
> --- busybox-1.6.1/sysklogd/syslogd.c	2007-06-30 11:06:35.000000000 -0400
> +++ busybox-1.6.1/sysklogd/syslogd.c	2007-08-09 15:16:33.000000000 -0400
> @@ -253,7 +253,7 @@
>  	if (new_tail < G.shbuf->size) {
>  		/* No need to move head if shbuf->head <= old_tail,
>  		 * else... */
> -		if (old_tail < G.shbuf->head && G.shbuf->head <= new_tail) {
> +		if (old_tail <= G.shbuf->head && G.shbuf->head <= new_tail) {
>  			/* ...need to move head forward */
>  			c = memchr(G.shbuf->data + new_tail, '\0',
>  					   G.shbuf->size - new_tail);

Unfortunately, this fix is incorrect. If tail == head, it means
that log buffer is empty and head should NOT be moved forward.

I spent an hour looking at this unholy mess of IPC shared buffer
which I don't like one iota. Oh well.

While I know how to fix it properly as-is, I'm in for more radical surgery.
head pointer is nuked, as it is used precisely in one place.

Please take a look at current svn. I tested and it works for me,
but extra testing is always good.

If it doesn't work, describe how I can reproduce it.
--
vda



More information about the busybox mailing list