]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: fix tailing non seekable files on certain systems
authorPádraig Brady <P@draigBrady.com>
Sun, 10 Dec 2017 04:18:22 +0000 (20:18 -0800)
committerPádraig Brady <P@draigBrady.com>
Mon, 11 Dec 2017 01:13:18 +0000 (17:13 -0800)
* 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
src/tail.c
tests/tail-2/tail-c.sh

diff --git a/NEWS b/NEWS
index 2a2515b7ef563658c74b61a241617409978e313b..3626c3da7d254f457f4e319357a2679133140177 100644 (file)
--- 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
index 536d0346d1d6a5720c1fb2b49a6175c2caf06ea7..642c448bf786eee48fdb4fd38a00f3130561a197 100644 (file)
@@ -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);
index 48060ff3f0c7275cbbd1783143d62fb989441cac..1edba57bfbc819fad33eb643814cfa6c4f8a4acf 100755 (executable)
 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