From: Jim Meyering Date: Sat, 16 Aug 2003 17:28:33 +0000 (+0000) Subject: An invalid initial value for *read_pos would result in X-Git-Tag: v5.0.91~190 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4be51104a8e353795716a63268d0d32aa97de7a;p=thirdparty%2Fcoreutils.git An invalid initial value for *read_pos would result in `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. --- diff --git a/src/tail.c b/src/tail.c index 1e551c5c94..7d83787070 100644 --- a/src/tail.c +++ b/src/tail.c @@ -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; }