diff options
author | marcel <marcel@FreeBSD.org> | 2006-10-21 18:05:06 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2006-10-21 18:05:06 +0000 |
commit | 0e4a74aceb8306ec64f6f5726ac8b8bcd0e8092f (patch) | |
tree | dfaf8ab619a3460340fa0c402e56ddec9715059a /usr.bin | |
parent | 0d077208a75b03dca53ec30a53225ba5127bde0b (diff) | |
download | FreeBSD-src-0e4a74aceb8306ec64f6f5726ac8b8bcd0e8092f.zip FreeBSD-src-0e4a74aceb8306ec64f6f5726ac8b8bcd0e8092f.tar.gz |
Better handle the -F case:
o When stat(2) fails (i.e. the file has been moved) there's no new
file with the same name yet, so keep showing the file that's open.
This yields the same behaviour as -f, for which we don't stat(2).
o When a new file with the same name has been created (i.e stat(2)
succeeds but the inode or device numbers differ from the opened
file), show any new lines in the opened file (i.e. the old or
rotated file) before reopening the new file.
These changes fix the observed behaviour that tail(1) doesn't show
the very last lines of the rotated (log) files.
PR: bin/101979
Tested by: Jos Backus <jos@catnook.com>
MFC after: 2 months
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tail/forward.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index e7bdd05..c79c438 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -348,13 +348,11 @@ follow(file_info_t *files, enum STYLE style, off_t off) if (! file->fp) continue; if (Fflag && file->fp && fileno(file->fp) != STDIN_FILENO) { - if (stat(file->file_name, &sb2) != 0) { - /* file was rotated, skip it until it reappears */ - continue; - } - if (sb2.st_ino != file->st.st_ino || - sb2.st_dev != file->st.st_dev || - sb2.st_nlink == 0) { + if (stat(file->file_name, &sb2) == 0 && + (sb2.st_ino != file->st.st_ino || + sb2.st_dev != file->st.st_dev || + sb2.st_nlink == 0)) { + show(file); file->fp = freopen(file->file_name, "r", file->fp); if (file->fp == NULL) { ierr(); |