Commit Graph

83 Commits

Author SHA1 Message Date
Ed Schouten
c7c497f1c5 Add missing static keywords to tail(1) 2011-11-06 08:17:17 +00:00
Jilles Tjoelker
54d34ff63d 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
2011-08-14 13:37:38 +00:00
Joel Dahl
da52b4caaf 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
2010-12-11 08:32:16 +00:00
Ed Schouten
b7946da96b Build usr.bin/ with WARNS=6 by default.
Also add some missing $FreeBSD$ to keep svn happy.
2010-01-02 10:27:05 +00:00
Ed Schouten
ef636796f6 ANSIfy various tools in usr.bin/.
Most of these tools properly build at WARNS=6, except for their K&R
function declarations. Fix this, so we can bump WARNS as well.
2010-01-02 10:09:20 +00:00
Christian Brueffer
cf6c5eebe7 Use our canonical .Dd format.
Submitted by:	Ulrich Spoerlein
2009-11-02 12:35:38 +00:00
Brian Somers
22da50cfc8 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
2009-06-05 09:08:53 +00:00
Tai-hwa Liang
e7356456ed Nuking the temporary pointer once it is properly tracked in local storage.
This should fix the double free() bug where there's no tailing newline(\n)
character:

	current# echo -n test | tail
	testAssertion failed: (run->magic == ARENA_RUN_MAGIC), function
	arena_dalloc, file /usr/src/lib/libc/stdlib/malloc.c, line 2448.
	Abort (core dumped)

Reviewed by:	kib
MFC after:	3 days
2007-11-22 01:51:46 +00:00
Philippe Charnier
f8c2d2bde1 initialize variables, WARNS=6 compliant 2007-11-02 18:06:51 +00:00
Konstantin Belousov
7ce8354a9b Fix various memory leaks.
Submitted by:	rdivacky
Obtained from:	OpenBSD
MFC after:	1 week
2007-10-17 09:52:08 +00:00
Ruslan Ermilov
61125887f3 Markup revision. 2006-12-24 19:18:52 +00:00
Marcel Moolenaar
d5d2cea180 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
2006-10-21 18:05:06 +00:00
Ruslan Ermilov
2982527d8b - Simplify the formatting in the SYNOPSIS.
- Add the forgotten new option in usage().
2006-06-30 08:19:26 +00:00
Florent Thoumie
aa1d7ce72f Add a -q option to suppress header lines when multiple files are specified.
Approved by:	cperciva (mentor)
MFC after:	1 week
2006-06-29 22:07:49 +00:00
Paul Saab
13829828e7 Unbreak tail -f on non-local filesystems. 2005-08-26 08:15:57 +00:00
Eivind Eklund
e1d27f08f1 Back out revision 1.19 and 1.20 until I find mental clarity to deal with
issues bde pointed out.
2005-06-01 20:34:06 +00:00
Eivind Eklund
ffef99c316 Remove an errno reset that became unnecessary.
Noticed by: juli
2005-05-26 22:49:08 +00:00
Eivind Eklund
d21ccc03c0 We are past 4.4BSD - use our new-found stat flags for pipes and fifos. 2005-05-26 22:14:37 +00:00
Ian Dowse
2bcccc224c Don't skip the initialisation of tl->len when we hit an EOF immediately
after allocating a new buffer. This bug caused `tail -r < /dev/null'
to core dump when the `J' malloc option is set, and also affected
any other input that was an exact multiple of 128k.
2005-03-20 22:08:52 +00:00
Xin LI
76628ce773 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
2005-02-04 14:01:06 +00:00
Ruslan Ermilov
a866e17077 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
Brian Somers
9e777bc6e2 Don't reprint file names unnecessarily.
PR:		75028
Submitted by:	mteterin at 250-217 dot customer dot cloud9 dot net
MFC after:	7 days
2005-01-12 04:06:31 +00:00
David Malone
06256619a5 Bump WARNS to 4 as this seems OK on the alpha now. 2005-01-10 20:22:37 +00:00
David Malone
d0990ea900 Cast size_t to off_t before adding them to avoid warnings on the alpha.
Use %ld and intmax_t for printing an off_t.
2005-01-10 20:19:46 +00:00
David Malone
a2fb00d93f 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.
2005-01-10 20:16:08 +00:00
Paul Richards
15a55f7926 Add support for following more than one file i.e.
tail -f file1 file2
2004-11-04 19:18:19 +00:00
Paul Richards
f45a52b3c3 Revert a WIP change that shouldn't have been in last commit. 2004-11-03 17:52:29 +00:00
Paul Richards
4bba8e595e Convert to ANSI style function definitions. 2004-11-03 15:23:11 +00:00
Ruslan Ermilov
6a3e8b0adc Mechanically kill hard sentence breaks. 2004-07-02 22:22:35 +00:00
David Greenman
7b51f66476 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
2003-08-14 11:02:03 +00:00
Mark Murray
96b5910f32 Revert part of the last commit. This fixes tail for pipes.
Submitted by:	joerg
2003-06-10 16:49:14 +00:00
Tim J. Robbins
f33ae51c77 When doing tail -F, return if the freopen() of the file fails instead of
trying to use a null file pointer.
2002-12-15 11:26:57 +00:00
Alfred Perlstein
e3d463662c revert WARNS=4, it makes the alpha compile sad. 2002-07-15 09:53:34 +00:00
Alfred Perlstein
d183dcb670 WARNS=4, add 2002-07-14 18:21:07 +00:00
Juli Mallett
6fc8ba94c6 Note that this appeared at least as early as PWB UNIX.
Use the literal string 'PWB UNIX', as we still have no .At macro for it.
2002-06-10 22:59:59 +00:00
David Malone
13685eeec2 Fix up vendor IDs.
Put a sequence point between writing to a variable and using it.
2002-04-13 20:59:48 +00:00
Murray Stokely
b77b9b9a90 GCC 3.1 cleanup - add a break after default: at the end of a switch
statement.
2002-04-08 08:34:00 +00:00
Warner Losh
3f330d7d1a remove __P 2002-03-22 01:42:45 +00:00
Mark Murray
814e3a92a9 WARNS=2 fixes, use __FBSDID(). 2001-12-12 00:01:16 +00:00
Ian Dowse
aee1bac713 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
2001-11-25 18:03:28 +00:00
Bill Fenner
8cd6778484 Allow "obsolete" (but commonly-used) command line style to be used
with -F, e.g. tail -1 -F /var/log/messages.

Submitted by:	Maxim Konovalov <maxim@macomnet.ru>
2001-10-02 06:22:01 +00:00
Andrey A. Chernov
bd9dc97512 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.
2001-09-01 22:22:45 +00:00
Ruslan Ermilov
d628d776c4 mdoc(7) police: utilize the new .Ex macro. 2001-08-15 09:09:47 +00:00
Ruslan Ermilov
625003720a mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 14:16:33 +00:00
Jonathan Lemon
a8fb4e2810 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.
2001-06-06 17:47:13 +00:00
Andrey A. Chernov
a74da62e70 Back out my fseeko -> fseek(END) change - we need to position on what we
displayed last, not to the end of file
2001-03-28 13:10:17 +00:00
Andrey A. Chernov
462da59fb1 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
2001-03-27 23:24:25 +00:00
David Malone
726098d35e Fix tail to work on files bigger than 2GB.
PR:		14786
Reviewed by:	iedowse
2001-03-27 20:37:34 +00:00
Andrey A. Chernov
6bea9ab43b Add comment explaining why size not passed directly to mmap, i.e. not relay
on its check.
KNF multi-line comments
(inspired by bde)
2001-03-27 15:53:48 +00:00
Andrey A. Chernov
1410c7cc9a Use SSIZE_MAX instead of INT_MAX, as kernel does ssize_t check
Better explanation comment of FIXME section
2001-03-27 01:16:44 +00:00