applying fix for:
authorPaul Fox <pgf@brightstareng.com>
Wed, 20 Jul 2005 19:46:32 +0000 (19:46 -0000)
committerPaul Fox <pgf@brightstareng.com>
Wed, 20 Jul 2005 19:46:32 +0000 (19:46 -0000)
    0000265: tail -f should keep following files even if they
                    were truncated

coreutils/tail.c

index e3f89d2eea5424c1661e02a6fb9ac54c337d3d59..d49539916be3c3f511228ab1ef82dbfa0435494a 100644 (file)
@@ -79,7 +79,19 @@ static void tail_xbb_full_write(const char *buf, size_t len)
 static ssize_t tail_read(int fd, char *buf, size_t count)
 {
        ssize_t r;
+       off_t current,end;
+       struct stat sbuf;
+       int ret;
 
+       end = current = lseek (fd, 0, SEEK_CUR);
+       if (!fstat(fd, &sbuf)){
+           end = sbuf.st_size;
+       }
+       if ( end < current) {
+               lseek(fd, 0, SEEK_SET);
+       } else {
+               lseek(fd, current, SEEK_SET);
+       }
        if ((r = safe_read(fd, buf, count)) < 0) {
                bb_perror_msg("read");
                status = EXIT_FAILURE;