aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/tail/forward.c
Commit message (Collapse)AuthorAgeFilesLines
* tail: fix the checks if the file was rotatedMariusz Zaborski2019-06-091-9/+19
| | | | | | | | | | | | | | | | | The freopen(3) was replaced with fileargs_open(3) and fclose(3). In the following function, we skip if the stream is standard in, so it is safe to do so. This also requires us to change the logic first to open the file and then check its status. The stat(2) is disallowed in capability mode. This commit unbrakes the -F option. The bug was introduced in the r348708. Reported by: pho Tested by: pho Notes: svn path=/head/; revision=348842
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Print file names without stdio buffering to avoid mixing buffered andJaakko Heinonen2013-06-091-2/+2
| | | | | | | | | | unbuffered ouput. PR: bin/176886 Reviewed by: mjg Notes: svn path=/head/; revision=251565
* Add missing static keywords to tail(1)Ed Schouten2011-11-061-3/+3
| | | | Notes: svn path=/head/; revision=227184
* tail: Fix crash if -F'ed file's filesystem disappears.Jilles Tjoelker2011-08-141-2/+4
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=224865
* Remove the advertising clause from UCB copyrighted files in usr.bin. ThisJoel Dahl2010-12-111-4/+0
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=216370
* Change the behaviour of -F slightly; it now persists (forever) inBrian Somers2009-06-051-61/+89
| | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=193488
* Better handle the -F case:Marcel Moolenaar2006-10-211-7/+5
| | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=163587
* Add a -q option to suppress header lines when multiple files are specified.Florent Thoumie2006-06-291-2/+3
| | | | | | | | Approved by: cperciva (mentor) MFC after: 1 week Notes: svn path=/head/; revision=160045
* Unbreak tail -f on non-local filesystems.Paul Saab2005-08-261-0/+10
| | | | Notes: svn path=/head/; revision=149485
* Save last displayed file by having the "last" pointer global and save itXin LI2005-02-041-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=141279
* Don't reprint file names unnecessarily.Brian Somers2005-01-121-4/+4
| | | | | | | | | PR: 75028 Submitted by: mteterin at 250-217 dot customer dot cloud9 dot net MFC after: 7 days Notes: svn path=/head/; revision=140101
* Some variables became unused or global in the last change to thisDavid Malone2005-01-101-9/+5
| | | | | | | | | | file. Remove the now redundant declarations. Add declarations for the new show and set_events functions and make them static. Notes: svn path=/head/; revision=139993
* Add support for following more than one file i.e.Paul Richards2004-11-041-88/+160
| | | | | | | tail -f file1 file2 Notes: svn path=/head/; revision=137225
* Convert to ANSI style function definitions.Paul Richards2004-11-031-5/+1
| | | | Notes: svn path=/head/; revision=137157
* Removed check of st_rdev changing in the -F support. st_rdev for regularDavid Greenman2003-08-141-1/+0
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=118900
* When doing tail -F, return if the freopen() of the file fails instead ofTim J. Robbins2002-12-151-0/+1
| | | | | | | trying to use a null file pointer. Notes: svn path=/head/; revision=107901
* GCC 3.1 cleanup - add a break after default: at the end of a switchMurray Stokely2002-04-081-0/+1
| | | | | | | statement. Notes: svn path=/head/; revision=94178
* remove __PWarner Losh2002-03-221-1/+1
| | | | Notes: svn path=/head/; revision=92922
* WARNS=2 fixes, use __FBSDID().Mark Murray2001-12-121-9/+11
| | | | Notes: svn path=/head/; revision=87712
* Since kqueue support was added to tail, the "-F" option (check forIan Dowse2001-11-251-30/+34
| | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=86888
* File positions are off_t nowdays, not long, so:Andrey A. Chernov2001-09-011-7/+7
| | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=82762
* o If the file being tailed is moved back to the original location,Jonathan Lemon2001-06-061-1/+3
| | | | | | | | resume using kqueue to monitor it, if possible. o auto-clear the read filter on EOF; this is needed when tailing a FIFO. Notes: svn path=/head/; revision=77823
* Back out my fseeko -> fseek(END) change - we need to position on what weAndrey A. Chernov2001-03-281-1/+1
| | | | | | | displayed last, not to the end of file Notes: svn path=/head/; revision=74933
* Restore part of my fix spammed in v1.23:Andrey A. Chernov2001-03-271-1/+1
| | | | | | | | | 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 Notes: svn path=/head/; revision=74885
* Fix tail to work on files bigger than 2GB.David Malone2001-03-271-34/+25
| | | | | | | | PR: 14786 Reviewed by: iedowse Notes: svn path=/head/; revision=74876
* Add comment explaining why size not passed directly to mmap, i.e. not relayAndrey A. Chernov2001-03-271-3/+9
| | | | | | | | | on its check. KNF multi-line comments (inspired by bde) Notes: svn path=/head/; revision=74863
* Use SSIZE_MAX instead of INT_MAX, as kernel does ssize_t checkAndrey A. Chernov2001-03-271-1/+3
| | | | | | | Better explanation comment of FIXME section Notes: svn path=/head/; revision=74834
* Treat mmap() error as fatal too, i.e. do exit(1) instead of returnAndrey A. Chernov2001-03-261-1/+1
| | | | Notes: svn path=/head/; revision=74830
* rlines() checks:Andrey A. Chernov2001-03-261-3/+10
| | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=74827
* Use EV_SET() macro to initialize kevent structure.Jonathan Lemon2001-02-281-7/+5
| | | | Notes: svn path=/head/; revision=73231
* Remove register keyword usage with prejudice.Jeroen Ruigrok van der Werven2000-12-031-2/+2
| | | | | | | | Modern compilers are smarter when it comes to allocating register usage. Notes: svn path=/head/; revision=69552
* Properly constify some static arrays.Jeroen Ruigrok van der Werven2000-12-021-2/+4
| | | | | | | Also #if out some sccsid's and add rcsid's. Notes: svn path=/head/; revision=69528
* Convert calls to match new kqueue API.Jonathan Lemon2000-07-181-5/+2
| | | | Notes: svn path=/head/; revision=63454
* If the kevent() registration fails (probably due to the underlyingJonathan Lemon2000-06-221-19/+53
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=61964
* Change <event.h> --> <sys/event.h>Jonathan Lemon2000-04-181-1/+1
| | | | Notes: svn path=/head/; revision=59373
* Change tail to use kqueue/kevent to obtain a notification whenJonathan Lemon2000-04-161-22/+51
| | | | | | | the file changes (when doing tail -{f|F}). Notes: svn path=/head/; revision=59291
* Add a new -F flag which is a superset of -f. It will cause tail toPeter Wemm1998-04-061-0/+16
| | | | | | | | | 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. Notes: svn path=/head/; revision=35081
* Change select(0, NULL, ...) to usleep()Andrey A. Chernov1997-12-121-5/+1
| | | | Notes: svn path=/head/; revision=31681
* Fix a misleading comment. Rename a variable to make more sense.Poul-Henning Kamp1997-10-111-5/+4
| | | | | | | Pointed out by by: bde Notes: svn path=/head/; revision=30292
* Fix a comment.Poul-Henning Kamp1997-09-151-1/+1
| | | | | | | Submitted by: Mikael Karpberg <karpen@ocean.campus.luth.se> Notes: svn path=/head/; revision=29460
* In these days, waiting one full second for more to appear is far too long.Poul-Henning Kamp1997-09-141-2/+2
| | | | | | | Let's try 250ms. Notes: svn path=/head/; revision=29402
* Sweep through the tree fixing mmap() usage:Alexander Langer1997-01-161-1/+1
| | | | | | | | | | | | | | | - 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 Notes: svn path=/head/; revision=21786
* complete err() changes, actually use warn() in most instancesAdam David1996-08-261-3/+3
| | | | Notes: svn path=/head/; revision=17833
* Dont forget to #include <err.h>Peter Wemm1996-08-251-0/+1
| | | | Notes: svn path=/head/; revision=17826
* Fix some bogons:Peter Wemm1996-08-251-11/+10
| | | | | | | | | | | - 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(). Notes: svn path=/head/; revision=17821
* one file somehow slipped by me in the previous commitAdam David1996-07-301-2/+4
| | | | | | | tidy up Notes: svn path=/head/; revision=17341
* BSD 4.4 Lite Usr.bin SourcesRodney W. Grimes1994-05-271-0/+234
Notes: svn path=/cvs2svn/branches/CHRISTOS/; revision=1590