Commit Graph

82 Commits

Author SHA1 Message Date
jilles
bb4511c618 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
29af67e52c 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
9b380e30d4 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
b2f1332428 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
brueffer
8169c493e6 Use our canonical .Dd format.
Submitted by:	Ulrich Spoerlein
2009-11-02 12:35:38 +00:00
brian
330bc8582d 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
avatar
5fe104598e 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
charnier
f991a17523 initialize variables, WARNS=6 compliant 2007-11-02 18:06:51 +00:00
kib
6c514f41e9 Fix various memory leaks.
Submitted by:	rdivacky
Obtained from:	OpenBSD
MFC after:	1 week
2007-10-17 09:52:08 +00:00
ru
94d62091c1 Markup revision. 2006-12-24 19:18:52 +00:00
marcel
0e4a74aceb 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
ru
7adc3589c2 - Simplify the formatting in the SYNOPSIS.
- Add the forgotten new option in usage().
2006-06-30 08:19:26 +00:00
flz
6d4f7a588c 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
ps
a234fe9966 Unbreak tail -f on non-local filesystems. 2005-08-26 08:15:57 +00:00
eivind
4587fc275c 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
bf8bf9051e Remove an errno reset that became unnecessary.
Noticed by: juli
2005-05-26 22:49:08 +00:00
eivind
1a8a2d84cd We are past 4.4BSD - use our new-found stat flags for pipes and fifos. 2005-05-26 22:14:37 +00:00
iedowse
316bdea082 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
delphij
aa38886281 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
ru
6cc4b6c220 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
brian
336b304268 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
dwmalone
cf651884b0 Bump WARNS to 4 as this seems OK on the alpha now. 2005-01-10 20:22:37 +00:00
dwmalone
eda4dfd490 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
dwmalone
86d764422f 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
4b813e782f Add support for following more than one file i.e.
tail -f file1 file2
2004-11-04 19:18:19 +00:00
paul
a13bf2199d Revert a WIP change that shouldn't have been in last commit. 2004-11-03 17:52:29 +00:00
paul
5386ac46ea Convert to ANSI style function definitions. 2004-11-03 15:23:11 +00:00
ru
fb1d8b3724 Mechanically kill hard sentence breaks. 2004-07-02 22:22:35 +00:00
dg
0ed08c885f 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
markm
d152e35c14 Revert part of the last commit. This fixes tail for pipes.
Submitted by:	joerg
2003-06-10 16:49:14 +00:00
tjr
e6e7b3cddd 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
0524c94cee revert WARNS=4, it makes the alpha compile sad. 2002-07-15 09:53:34 +00:00
alfred
adf0fb9f4e WARNS=4, add 2002-07-14 18:21:07 +00:00
jmallett
241a475e6f 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
dwmalone
ec9302ee87 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
cc26525bb5 GCC 3.1 cleanup - add a break after default: at the end of a switch
statement.
2002-04-08 08:34:00 +00:00
imp
0b20191705 remove __P 2002-03-22 01:42:45 +00:00
markm
d7e4e2a006 WARNS=2 fixes, use __FBSDID(). 2001-12-12 00:01:16 +00:00
iedowse
f9343b3578 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
fenner
efade0125d 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
ache
46ab006323 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
ru
bde8ec1b70 mdoc(7) police: utilize the new .Ex macro. 2001-08-15 09:09:47 +00:00
ru
36f138439b mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 14:16:33 +00:00
jlemon
08bbb9b6f5 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
ache
323ee87c02 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
ache
b3c7f151dc 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
dwmalone
17ede005a9 Fix tail to work on files bigger than 2GB.
PR:		14786
Reviewed by:	iedowse
2001-03-27 20:37:34 +00:00
ache
aec4c6204b 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
ache
8a3f432b98 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
ache
5b94e50e9a Treat mmap() error as fatal too, i.e. do exit(1) instead of return 2001-03-26 19:36:27 +00:00