bug#79508: [PATCH] tail: fix seeking backward

Hannes Braun via GNU coreutils Bug Reports <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <[email protected]>
* src/tail.c (file_lines): Seek to the previous block instead of the
beginning (or a little before) of the block that was just scanned.
Otherwise, the same block is read and scanned (at least partially)
again. This bug was introduced by commit v9.7-219-g976f8abc1.
---
 src/tail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tail.c b/src/tail.c
index b8bef1d91..c7779c77d 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -596,7 +596,7 @@ file_lines (char const *prettyname, int fd, struct stat const *sb,
           goto free_buffer;
         }
 
-      pos = xlseek (fd, -bufsize, SEEK_CUR, prettyname);
+      pos = xlseek (fd, -(bufsize + bytes_read), SEEK_CUR, prettyname);
       bytes_read = read (fd, buffer, bufsize);
       if (bytes_read < 0)
         {
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.