diff options
author | Jim Meyering <jim@meyering.net> | 2003-08-16 17:28:33 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-08-16 17:28:33 +0000 |
commit | f4be51104a8e353795716a63268d0d32aa97de7a (patch) | |
tree | 8ee77c7ff24685bb4055e1b0ac2b661816b27806 /src | |
parent | d14d30c58f881c006d919710cfd66639f4dbb6bd (diff) | |
download | coreutils-f4be51104a8e353795716a63268d0d32aa97de7a.tar.xz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/tail.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/tail.c b/src/tail.c index 1e551c5c9..7d8378707 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; } |