On Tuesday 02 October 2007 10:52, Kazuo TAKADA wrote:
> Hi,
>
> I found bug in busybox 1.7.2 and before.
> The tail command can't handle the /proc directory and doesn't return
> from a while loop.
>
> For example:
> ----------------------------------------
> % ./busybox tail /proc/meminfo
> (It doesn't exit...)
> ----------------------------------------
>
> The patch below can resolve this problem.
>
> ----------------------------------------------------------------------
> --- coreutils/tail.c.orig 2007-09-03 20:48:40.000000000 +0900
> +++ coreutils/tail.c 2007-10-02 17:54:34.000000000 +0900
> @@ -51,7 +51,7 @@
> struct stat sbuf;
>
> end = current = lseek(fd, 0, SEEK_CUR);
> - if (!fstat(fd, &sbuf))
> + if (!fstat(fd, &sbuf) && sbuf.st_size)
> end = sbuf.st_size;
> lseek(fd, end < current ? 0 : current, SEEK_SET);
> r = safe_read(fd, buf, count);
> ----------------------------------------------------------------------
I am applying this patch (see attached). Does it work for you?
--
vda
diff -urN busybox-1.7.2/coreutils/tail.c busybox-1.7.2-tail/coreutils/tail.c
--- busybox-1.7.2/coreutils/tail.c 2007-09-03 12:48:40.000000000 +0100
+++ busybox-1.7.2-tail/coreutils/tail.c 2007-10-02 11:13:31.000000000 +0100
@@ -47,13 +47,15 @@
static ssize_t tail_read(int fd, char *buf, size_t count)
{
ssize_t r;
- off_t current, end;
+ off_t current;
struct stat sbuf;
- end = current = lseek(fd, 0, SEEK_CUR);
- if (!fstat(fd, &sbuf))
- end = sbuf.st_size;
- lseek(fd, end < current ? 0 : current, SEEK_SET);
+ /* (good comment is missing here) */
+ current = lseek(fd, 0, SEEK_CUR);
+ if (fstat(fd, &sbuf) == 0 && sbuf.st_size)
+ if (sbuf.st_size < current)
+ lseek(fd, 0, SEEK_SET);
+
r = safe_read(fd, buf, count);
if (r < 0) {
bb_perror_msg(bb_msg_read_error);
@@ -67,8 +69,12 @@
static unsigned eat_num(const char *p)
{
- if (*p == '-') p++;
- else if (*p == '+') { p++; G.status = EXIT_FAILURE; }
+ if (*p == '-')
+ p++;
+ else if (*p == '+') {
+ p++;
+ G.status = EXIT_FAILURE;
+ }
return xatou_sfx(p, tail_suffixes);
}
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox