mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-01 08:27:59 +00:00
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.
This commit is contained in:
parent
aacdc613e5
commit
eb1c943900
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35081
@ -48,5 +48,5 @@ int lines __P((FILE *, off_t));
|
||||
void ierr __P((void));
|
||||
void oerr __P((void));
|
||||
|
||||
extern int fflag, rflag, rval;
|
||||
extern int Fflag, fflag, rflag, rval;
|
||||
extern char *fname;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,11 @@
|
||||
.Nd display the last part of a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl f Li | Fl r
|
||||
.Oo
|
||||
.Fl F |
|
||||
.Fl f |
|
||||
.Fl r
|
||||
.Oc
|
||||
.Oo
|
||||
.Fl b Ar number |
|
||||
.Fl c Ar number |
|
||||
@ -91,6 +95,20 @@ data to be appended to the input.
|
||||
The
|
||||
.Fl f
|
||||
option is ignored if the standard input is a pipe, but not if it is a FIFO.
|
||||
.It Fl F
|
||||
The
|
||||
.Fl F
|
||||
option implies the
|
||||
.Fl f
|
||||
option, but
|
||||
.Nm
|
||||
will also check to see if the file being followed has been renamed or rotated.
|
||||
The file is closed and reopened when
|
||||
.Nm
|
||||
detects that the filename being read from has a new inode number.
|
||||
The
|
||||
.Fl F
|
||||
option is ignored if reading from standard input rather than a file.
|
||||
.It Fl n Ar number
|
||||
The location is
|
||||
.Ar number
|
||||
@ -136,6 +154,7 @@ utility is expected to be a superset of the
|
||||
.St -p1003.2-92
|
||||
specification.
|
||||
In particular, the
|
||||
.Fl F ,
|
||||
.Fl b
|
||||
and
|
||||
.Fl r
|
||||
|
@ -54,7 +54,7 @@ static char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <err.h>
|
||||
#include "extern.h"
|
||||
|
||||
int fflag, rflag, rval;
|
||||
int Fflag, fflag, rflag, rval;
|
||||
char *fname;
|
||||
|
||||
static void obsolete __P((char **));
|
||||
@ -107,8 +107,11 @@ main(argc, argv)
|
||||
|
||||
obsolete(argv);
|
||||
style = NOTSET;
|
||||
while ((ch = getopt(argc, argv, "b:c:fn:r")) != -1)
|
||||
while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1)
|
||||
switch(ch) {
|
||||
case 'F': /* -F is superset of (and implies) -f */
|
||||
Fflag = fflag = 1;
|
||||
break;
|
||||
case 'b':
|
||||
ARG(512, FBYTES, RBYTES);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user