History log of /freebsd-10.1-release/usr.bin/tail/forward.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 251565 09-Jun-2013 jh

Print file names without stdio buffering to avoid mixing buffered and
unbuffered ouput.

PR: bin/176886
Reviewed by: mjg


# 227184 06-Nov-2011 ed

Add missing static keywords to tail(1)


# 224865 14-Aug-2011 jilles

tail: Fix crash if -F'ed file's filesystem disappears.

If tail notices that a file it is following no longer exists (because stat()
fails), it will output any final lines and then close the file. If the read
operation also causes an error, such as when the filesystem is forcefully
unmounted, it closes the file as well, leading to fclose(NULL) and a
segmentation fault.

PR: bin/159750
Submitted by: swills
Approved by: re (kib)
MFC after: 1 week


# 216370 11-Dec-2010 joel

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# 193488 05-Jun-2009 brian

Change the behaviour of -F slightly; it now persists (forever) in
trying to open files rather than giving up when it encounters an
error. ENOENT errors are not reported.

As a result, files that are moved away then recreated are not at
risk of being 'lost' to tail. Files that are recreated and
temporarily have unreadable permissions will be shown when they
are fixed.

This behaviour is consistent with the GNU version of tail but
without the verbiage that goes with the GNU version.

This change also fixes error messages accompanying -f and -F.
They no longer report problems with (null)!

MFC after: 3 weeks


# 163587 21-Oct-2006 marcel

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


# 160045 29-Jun-2006 flz

Add a -q option to suppress header lines when multiple files are specified.

Approved by: cperciva (mentor)
MFC after: 1 week


# 149485 26-Aug-2005 ps

Unbreak tail -f on non-local filesystems.


# 141279 04-Feb-2005 delphij

Save last displayed file by having the "last" pointer global and save it
during we show the first file's tail. Instead of:

tarsier% tail -f 1 2
==> 1 <==
foo
bar

==> 2 <==
bar
foo

==> 2 <==
bar2
foo2

Now with this change, we have:

tarsier% tail -f 1 2
==> 1 <==
foo
bar

==> 2 <==
bar
foo
bar2
foo2

While I'm there, move a comment to where it should belong to. Also,
const'ify the "last" static because we will never need to change the
contents it points to.

MFC After: 1 week


# 140101 12-Jan-2005 brian

Don't reprint file names unnecessarily.

PR: 75028
Submitted by: mteterin at 250-217 dot customer dot cloud9 dot net
MFC after: 7 days


# 139993 10-Jan-2005 dwmalone

Some variables became unused or global in the last change to this
file. Remove the now redundant declarations.

Add declarations for the new show and set_events functions and make
them static.


# 137225 04-Nov-2004 paul

Add support for following more than one file i.e.
tail -f file1 file2


# 137157 03-Nov-2004 paul

Convert to ANSI style function definitions.


# 118900 14-Aug-2003 dg

Removed check of st_rdev changing in the -F support. st_rdev for regular
files is usually the first direct block pointer. Since FreeBSD does
automatic block reallocation to reduce filesystem fragmentation, the
file being tailed can be relocated to different blocks 'on-the-fly',
making the check for st_rdev unreliable. The result of this bug is
tail -F pseudo-randomnly thinking the file was rotated when it wasn't,
and as a result, spews out the entire file trying to catch up.

MFC after: 3 days


# 107901 15-Dec-2002 tjr

When doing tail -F, return if the freopen() of the file fails instead of
trying to use a null file pointer.


# 94178 08-Apr-2002 murray

GCC 3.1 cleanup - add a break after default: at the end of a switch
statement.


# 92922 21-Mar-2002 imp

remove __P


# 87712 11-Dec-2001 markm

WARNS=2 fixes, use __FBSDID().


# 86888 25-Nov-2001 iedowse

Since kqueue support was added to tail, the "-F" option (check for
renames/rotations) only detected cases where the file itself was
moved or deleted. If part of the path to the file (or a symlink
in the path) was changed instead, tail would not notice.

Fix this by ensuring that we stat the path at least once every
second in the -F case to check for changes. We still use kqueue
when possible to inform us quickly when the file has changed.

PR: bin/24955
Submitted by: Maxim Konovalov <maxim@macomnet.ru>
MFC after: 1 week


# 82762 01-Sep-2001 ache

File positions are off_t nowdays, not long, so:
long -> off_t
strtol -> strtoll
fseek -> fseeko

NOTE: that fseek not works for >long offsets files per POSIX:

[EOVERFLOW] For fseek( ), the resulting file offset would be a value which
cannot be represented correctly in an object of type long.


# 77823 06-Jun-2001 jlemon

o If the file being tailed is moved back to the original location,
resume using kqueue to monitor it, if possible.
o auto-clear the read filter on EOF; this is needed when tailing a FIFO.


# 74933 28-Mar-2001 ache

Back out my fseeko -> fseek(END) change - we need to position on what we
displayed last, not to the end of file


# 74885 27-Mar-2001 ache

Restore part of my fix spammed in v1.23:
fseeko(file_size, SEEK_SET) -> fseek(0L, SEEK_END)
1) File may grows between operations, so fseeko to file_size may miss
2) 0L, SEEK_END is the same code using in tail in all other places


# 74876 27-Mar-2001 dwmalone

Fix tail to work on files bigger than 2GB.

PR: 14786
Reviewed by: iedowse


# 74863 27-Mar-2001 ache

Add comment explaining why size not passed directly to mmap, i.e. not relay
on its check.
KNF multi-line comments
(inspired by bde)


# 74834 26-Mar-2001 ache

Use SSIZE_MAX instead of INT_MAX, as kernel does ssize_t check
Better explanation comment of FIXME section


# 74830 26-Mar-2001 ache

Treat mmap() error as fatal too, i.e. do exit(1) instead of return


# 74827 26-Mar-2001 ache

rlines() checks:
1) really check for size overflow by checking negative value.
2) since mmap() not support files over INT_MAX size, add check for it
until either mmap() will be fixed or tail will be rewritted to handle
large files alternatively.
3) replace fseek(... file_size, SEEK_SET) with fseek(... 0L, SEEK_END)
to avoid off_t -> long cast
4) Use exit() if file is too big instead of warning and wrong logic
afterwards.


# 73231 28-Feb-2001 jlemon

Use EV_SET() macro to initialize kevent structure.


# 69552 03-Dec-2000 asmodai

Remove register keyword usage with prejudice.
Modern compilers are smarter when it comes to allocating register
usage.


# 69528 02-Dec-2000 asmodai

Properly constify some static arrays.

Also #if out some sccsid's and add rcsid's.


# 63454 18-Jul-2000 jlemon

Convert calls to match new kqueue API.


# 61964 22-Jun-2000 jlemon

If the kevent() registration fails (probably due to the underlying
filesystem not being kq-aware), then fall back to using sleep. This
allows tail to work with NFS filesystems again without chewing up CPU time.

When given the -F flag, resort to sleep/stat after the file was moved
or deleted. This allows a window where the file being tailed does not
exist at all, which is typically the case during log rotation. Switch
back to using kq (if possible) after the file is reopened.


# 59373 18-Apr-2000 jlemon

Change <event.h> --> <sys/event.h>


# 59291 16-Apr-2000 jlemon

Change tail to use kqueue/kevent to obtain a notification when
the file changes (when doing tail -{f|F}).


# 35081 06-Apr-1998 peter

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.


# 31681 12-Dec-1997 ache

Change select(0, NULL, ...) to usleep()


# 30292 11-Oct-1997 phk

Fix a misleading comment. Rename a variable to make more sense.
Pointed out by by: bde


# 29460 15-Sep-1997 phk

Fix a comment.

Submitted by: Mikael Karpberg <karpen@ocean.campus.luth.se>


# 29402 14-Sep-1997 phk

In these days, waiting one full second for more to appear is far too long.
Let's try 250ms.


# 21786 16-Jan-1997 alex

Sweep through the tree fixing mmap() usage:

- Use MAP_FAILED instead of the constant -1 to indicate
failure (required by POSIX).
- Removed flag arguments of '0' (required by POSIX).
- Fixed code which expected an error return of 0.
- Fixed code which thought any address with the high bit set
was an error.
- Check for failure where no checks were present.

Discussed with: bde


# 17833 26-Aug-1996 adam

complete err() changes, actually use warn() in most instances


# 17826 25-Aug-1996 peter

Dont forget to #include <err.h>


# 17821 25-Aug-1996 peter

Fix some bogons:
- timeval in select loop was depending on not having the remaining time
returned from select(), causing a busy spin on an implementation that
does implement it.
- the err() usage was pretty bogus, some of the error messages had
strerror attached manually and then reattached by err().


# 17341 30-Jul-1996 adam

one file somehow slipped by me in the previous commit
tidy up


# 1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.


# 1590 27-May-1994 rgrimes

BSD 4.4 Lite Usr.bin Sources