From e44df9d3f52d261719786ba54d91cca142389daa Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sat, 9 Dec 2017 20:18:22 -0800 Subject: [PATCH] tail: fix tailing non seekable files on certain systems * src/tail.c (tail_bytes): On systems were blksize_t is unsigned and the same size or wider than off_t (android for example), our initialized (off_t) -1 would be promoted to unsigned before comparison, and thus fail to follow the appropriate path. * tests/tail-2/tail-c.sh: Add a test case. * NEWS: Mention the fix. This issue was introduced in commit v8.23-47-g2662702 Reported at https://github.com/termux/termux-app/issues/233 --- NEWS | 4 ++++ src/tail.c | 2 +- tests/tail-2/tail-c.sh | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 2a2515b7ef..3626c3da7d 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,10 @@ GNU coreutils NEWS -*- outline -*- stty no longer crashes when processing settings with -F also specified. [bug introduced in fileutils-4.0] + tail --bytes again supports non seekable inputs on all systems. + On systems like android it always tried to process as seekable inputs. + [bug introduced in coreutils-8.24] + timeout will again notice its managed command exiting, even when invoked with blocked CHLD signal, or in a narrow window where this CHLD signal from the exiting child was missed. In each case diff --git a/src/tail.c b/src/tail.c index 536d0346d1..642c448bf7 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1855,7 +1855,7 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes, else if ((current_pos = lseek (fd, -n_bytes, SEEK_END)) != -1) end_pos = current_pos + n_bytes; } - if (end_pos <= ST_BLKSIZE (stats)) + if (end_pos <= (off_t) ST_BLKSIZE (stats)) return pipe_bytes (pretty_filename, fd, n_bytes, read_pos); if (current_pos == -1) current_pos = xlseek (fd, 0, SEEK_CUR, pretty_filename); diff --git a/tests/tail-2/tail-c.sh b/tests/tail-2/tail-c.sh index 48060ff3f0..1edba57bfb 100755 --- a/tests/tail-2/tail-c.sh +++ b/tests/tail-2/tail-c.sh @@ -20,15 +20,19 @@ print_ver_ tail # Make sure it works on funny files in /proc and /sys. - for file in /proc/version /sys/kernel/profiling; do if test -r $file; then cp -f $file copy && - tail -c -1 copy > exp1 || framework_failure_ + tail -c -1 copy > exp || framework_failure_ - tail -c -1 $file > out1 || fail=1 - compare exp1 out1 || fail=1 + tail -c -1 $file > out || fail=1 + compare exp out || fail=1 fi done +# Make sure it works for pipes +printf '123456' | tail -c3 > out || fail=1 +printf '456' > exp || framework_failure_ +compare exp out || fail=1 + Exit $fail -- 2.47.2