aboutsummaryrefslogtreecommitdiff
path: root/coreutils/tail.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-02 10:17:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-02 10:17:56 +0000
commit368a12efc24d9e9c758ee99239f79e5f443e6c0e (patch)
tree92fca54674a54e3accca4da4088b7aaa693038c9 /coreutils/tail.c
parentebeaea04dc2b2e75048262355fbfb970e5c92595 (diff)
downloadbusybox-368a12efc24d9e9c758ee99239f79e5f443e6c0e.tar.gz
tail: work correctly on /proc files (Kazuo TAKADA <kztakada@sm.sony.co.jp>)
Diffstat (limited to 'coreutils/tail.c')
-rw-r--r--coreutils/tail.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 74e14232d..8a112346d 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -47,13 +47,16 @@ static void tail_xprint_header(const char *fmt, const char *filename)
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);
+ /* (A good comment is missing here) */
+ current = lseek(fd, 0, SEEK_CUR);
+ /* /proc files report zero st_size, don't lseek them. */
+ 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 +70,12 @@ static const char header_fmt[] ALIGN1 = "\n==> %s <==\n";
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);
}