diff options
author | peter <peter@FreeBSD.org> | 1998-04-06 16:13:49 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1998-04-06 16:13:49 +0000 |
commit | 7c3222498acb0b317b49cca6311ffb697172d7ca (patch) | |
tree | ad45ab72c9092b4dc1f619c3792adae6338de17b /usr.bin/tail/forward.c | |
parent | 6e3ec235ff85715b4f3346989bae94f7e0aaacfe (diff) | |
download | FreeBSD-src-7c3222498acb0b317b49cca6311ffb697172d7ca.zip FreeBSD-src-7c3222498acb0b317b49cca6311ffb697172d7ca.tar.gz |
Add a new -F flag which is a superset of -f. It will cause tail to
stat() the file being followed and do a close/reopen if the file has been
renamed and/or rotated. This is damn useful for leaving running on files
in /var/log when newsyslog(8) rotates them.
Diffstat (limited to 'usr.bin/tail/forward.c')
-rw-r--r-- | usr.bin/tail/forward.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index 1c4020d..31f5ea6 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -86,6 +86,7 @@ forward(fp, style, off, sbp) { register int ch; struct timeval interval; + struct stat sb2; switch(style) { case FBYTES: @@ -179,6 +180,21 @@ forward(fp, style, off, sbp) (void) usleep(250000); clearerr(fp); + + if (Fflag && fileno(fp) != STDIN_FILENO && + stat(fname, &sb2) != -1) { + if (sb2.st_ino != sbp->st_ino || + sb2.st_dev != sbp->st_dev || + sb2.st_rdev != sbp->st_rdev || + sb2.st_nlink == 0) { + fp = freopen(fname, "r", fp); + if (fp == NULL) { + ierr(); + break; + } + *sbp = sb2; + } + } } } |