nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1(NB: we omit the new test, in order to avoid rerunning autoconf.)
2
3From 914972e80dbf82aac9ffe3ff1f67f1028e1a788b Mon Sep 17 00:00:00 2001
4From: Hannes Braun <hannes@hannesbraun.net>
5Date: Wed, 24 Sep 2025 21:20:49 +0200
6Subject: [PATCH] tail: fix tailing larger number of lines in regular files
7
8* src/tail.c (file_lines): Seek to the previous block instead of the
9beginning (or a little before) of the block that was just scanned.
10Otherwise, the same block is read and scanned (at least partially)
11again. This bug was introduced by commit v9.7-219-g976f8abc1.
12* tests/tail/basic-seek.sh: Add a new test.
13* tests/local.mk: Reference the new test.
14* NEWS: mention the bug fix.
15---
16 NEWS | 4 ++++
17 src/tail.c | 2 +-
18 tests/local.mk | 1 +
19 tests/tail/basic-seek.sh | 28 ++++++++++++++++++++++++++++
20 4 files changed, 34 insertions(+), 1 deletion(-)
21 create mode 100755 tests/tail/basic-seek.sh
22
23diff --git a/NEWS b/NEWS
24index 7a1a73113e839f010aa6c734e6f07da68827b953..dc1d26879327761d35499815776477771758edd4 100644
25--- a/NEWS
26+++ b/NEWS
27@@ -7,6 +7,10 @@ GNU coreutils NEWS -*- outline -*-
28 `basenc --base58` would not operate correctly with input > 15561475 bytes.
29 [bug introduced with --base58 in coreutils-9.8]
30
31+ 'tail' outputs the correct number of lines again for non-small -n values.
32+ Previously it may have output too few lines.
33+ [bug introduced in coreutils-9.8]
34+
35
36 * Noteworthy changes in release 9.8 (2025-09-22) [stable]
37
38diff --git a/src/tail.c b/src/tail.c
39index b8bef1d91cdb6cde2b666b6c1575376e075eaeb8..c7779c77dfe4cf5a672a265b6e796c7153590170 100644
40--- a/src/tail.c
41+++ b/src/tail.c
42@@ -596,7 +596,7 @@ file_lines (char const *prettyname, int fd, struct stat const *sb,
43 goto free_buffer;
44 }
45
46- pos = xlseek (fd, -bufsize, SEEK_CUR, prettyname);
47+ pos = xlseek (fd, -(bufsize + bytes_read), SEEK_CUR, prettyname);
48 bytes_read = read (fd, buffer, bufsize);
49 if (bytes_read < 0)
50 {