[PATCH] tail can't handle the /proc directory
Kazuo TAKADA
kztakada at sm.sony.co.jp
Tue Oct 2 09:52:23 UTC 2007
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);
----------------------------------------------------------------------
'man fstat' said:
>Linux Notes
:
> For most files under the /proc directory, stat() does not return the
> file size in the st_size field; instead the field is returned with
> the value 0.
Therefore, fstat() returns 0(=SUCCESS) and sbuf.st_size is set with
value 0. As a result, 'end' becomes 0 and lseek(fd, 0, SEEK_SET) is
executed over and over again.
Best regards,
Kazuo TAKADA
More information about the busybox
mailing list