]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
An invalid initial value for *read_pos would result in
authorJim Meyering <jim@meyering.net>
Sat, 16 Aug 2003 17:28:33 +0000 (17:28 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 16 Aug 2003 17:28:33 +0000 (17:28 +0000)
`tail -n0 -f FILE' and `tail -c0 -f FILE' doing what amounted to a
busy-wait rather than sleeping between iterations.  The bug manifests
itself only when tailing regular files that are initially nonempty.

(tail_bytes): Set *read_pos to new file offset after
each xlseek call.
(tail_lines): Likewise, after lseek calls.

src/tail.c

index 1e551c5c94cd54e2783108bd174cdc4a60cdfb6a..7d8378707024eb599279e1cd7d124347241929a2 100644 (file)
@@ -1138,13 +1138,13 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes,
                 more bytes than have been requested.  So reposition the
                 file pointer to the incoming current position and print
                 everything after that.  */
-             xlseek (fd, current_pos, SEEK_SET, pretty_filename);
+             *read_pos = xlseek (fd, current_pos, SEEK_SET, pretty_filename);
            }
          else
            {
              /* There are more bytes remaining than were requested.
                 Back up.  */
-             xlseek (fd, -nb, SEEK_END, pretty_filename);
+             *read_pos = xlseek (fd, -nb, SEEK_END, pretty_filename);
            }
          *read_pos += dump_remainder (pretty_filename, fd, n_bytes);
        }
@@ -1194,12 +1194,15 @@ tail_lines (const char *pretty_filename, int fd, uintmax_t n_lines,
           && (start_pos = lseek (fd, (off_t) 0, SEEK_CUR)) != -1
           && start_pos < (end_pos = lseek (fd, (off_t) 0, SEEK_END)))
        {
+         *read_pos = end_pos;
          if (end_pos != 0 && file_lines (pretty_filename, fd, n_lines,
                                          start_pos, end_pos, read_pos))
            return 1;
        }
       else
-       return pipe_lines (pretty_filename, fd, n_lines, read_pos);
+       {
+         return pipe_lines (pretty_filename, fd, n_lines, read_pos);
+       }
     }
   return 0;
 }