summaryrefslogtreecommitdiffstats
path: root/text-utils/tailf.c
Commit message (Collapse)AuthorAgeFilesLines
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: simplify if clauses [oclint]Sami Kerola2016-07-211-5/+3Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* tailf: Fix previously adjusted segfault patchTobias Stoeckmann2016-07-191-1/+1
| | | | | | | | | | | | | | | | Casting the value to be checked to size_t renders the check useless. If st_size is SIZE_MAX+1, it will be truncated to 0 and the check succeeds. In fact, this check can never be false because every value stored in a size_t is smaller or equal to SIZE_MAX. I think this adjustment was meant to fix a compiler warning for 64 bit systems for which sizeof(off_t) is sizeof(size_t), but the signedness differs. Going unconditionally to the greatest possible unsigned int type if st_size is positive (off_t is signed) will fix this issue. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* tailf: Fix segmentation fault in tailf on 32 bitTobias Stoeckmann2016-07-141-2/+5
| | | | | | | | | | | | | tailf crashes with a segmentation fault when used with a file that is exactly 4GB in size due to an integer overflow between off_t and size_t: $ dd if=/dev/zero of=tailf.crash bs=1 count=1 seek=4294967295 $ tailf tailf.crash Segmentation fault $ _ Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: fix open() return value check [coverity scan]Karel Zak2015-08-051-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: deprecatedRuediger Meier2015-03-161-4/+10
| | | | | | | | | | | | We want to remove it in 2 years, March 2017. See discussion "tailf, really needed?" http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/10967 [kzak@redhat.com: - move warning to usage()] Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl> Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: use size_t and fwrite()Karel Zak2015-03-051-18/+14Star
| | | | | | | Let's use size_t for number of output lines and use fwrite() rather than while() { putchar() }; Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: ensure file argument really is a fileSami Kerola2015-03-051-1/+2
| | | | | | | | | | The tailf(1) never worked very well with block or character devices, sockets, fifos and such. Now after mmap() is used to find last lines even the little command used to work for example pipes is broken, so test the tailf is asked to follow a file and when not fail. That said symlinks are OK, as long they point to a file. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* tailf: do not allow minus signed last lines argumentSami Kerola2015-03-051-11/+13
| | | | | | | | | | | Before mmap() the command behavior was not completely correct, as demonstrated below, and after the mmap() it tried to print some eighteen quintillion lines. $ tailf -n-1 x tailf: cannot allocate 18446744073709543424 bytes: Cannot allocate memory Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* tailf: count last lines correctly at initial print outSami Kerola2015-03-051-41/+36Star
| | | | | | | | | When last lines happen to be greater than string buffer size for fgets() the number of printed lines resulted to too few. To avoid miscounts due insufficient buffer size use mmap() to map the whole file and rewind until requested number of new lines is found. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: grammarize and harmonize the stat error messageBenno Schulenberg2015-02-021-2/+2
| | | | | | | | | The message "stat failed %s" seems to say that stat() failed to do something, or failed to pass a test, but of course it means that the statting of something failed. So say so. Also make two very similar messages equal to this one. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* tailf: slice up the usage text for ease of translationBenno Schulenberg2015-01-061-10/+9Star
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+3
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: use manual tail usage() macroSami Kerola2014-10-011-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: use version printing macro everywhereSami Kerola2014-10-011-2/+1Star
| | | | | | | Only mount, umount, and blkid remains not using the macro because they are print also library references. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/c.h: prefer nanosleep() over usleep()Karel Zak2014-01-241-1/+1
| | | | | | | | | | | | | | Let's use nanosleep() although if usleep() exists. The nanosleep function does no interact with signals and other timers. The patch introduces xusleep() as replacement to libc (or our fallback) usleep(). Yes, we don't want to use struct timespec + nanosleep() everywhere in code as nano-time resolution is useless for us. The patch also enlarges delays in some busy wait loops. It seems enough to try read/write 4x per second. Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix variable and function declarations [smatch scan]Sami Kerola2013-04-091-5/+5
| | | | | | | | | | | | | | | | | disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code fdisks/sfdisk.c:982:5: warning: mixing declarations and code fdisks/sfdisk.c:1254:5: warning: mixing declarations and code fdisks/sfdisk.c:1564:5: warning: mixing declarations and code lib/mbsalign.c:279:7: warning: mixing declarations and code libblkid/src/devname.c:378:17: warning: mixing declarations and code libfdisk/src/alignment.c:219:9: warning: mixing declarations and code term-utils/wall.c:111:9: warning: mixing declarations and code text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks' text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line' text-utils/rev.c:105:9: warning: mixing declarations and code text-utils/tailf.c:245:9: warning: mixing declarations and code Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/c: move usleep() fallback to c.hKarel Zak2012-10-221-1/+0Star
| | | | | | To make it available everywhere in code. Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: fix compiler warning [-Wmissing-prototypes]Karel Zak2012-07-161-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* translation: unify file open error messagesSami Kerola2012-07-161-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* translation: unify stat error messagesSami Kerola2012-07-161-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* text-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* tailf: harmonize option argument and explanation in usage messageBenno Schulenberg2011-08-151-2/+2
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* tailf: support --lines 0Karel Zak2011-03-181-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: fix open() return value check [coverity scan]Karel Zak2011-03-111-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: fix memmove() usageKarel Zak2011-03-081-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: use long optionsSami Kerola2011-03-081-19/+69
| | | | | | | | | | This was TODO item from commit 947a7c9c. The patch also introduces version and help switches. [kzak@redhat.com: rewrite old_style_option()] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: provide alternatives for err, errx, warn and warnxFabian Groffen2011-02-141-1/+1
| | | | | | | | Solaris lacks err, errx, warn and warnx. This also means the err.h header doesn't exist. Removed err.h include from all files, and included err.h from c.h instead if it exists, otherwise alternatives are provided. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
* tailf: use xalloc for memory allocationDavidlohr Bueso2010-11-011-2/+3
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* tailf: fixed timing issue that could cause duplicate data outputDima Kogan2010-08-201-1/+10
| | | | | | | | | | | | | | The issue is that in roll_file() we fstat() to find the file size, then read() as much data as we can and then use the previously saved file size to mark our position. The bug occurs if we read past the file size reported by fstat() because more data has arrived while we were reading it. The attached patch uses the current file position as the location marker instead, with some extra logic to handle tailing truncated files. [kzak@redhat.com: - fix coding style] Signed-off-by: Dima Kogan <dkogan@cds.caltech.edu> Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: fix printf formatMike Frysinger2009-11-231-1/+1
| | | | | | | ssize_t types are shown with %zd, not %ld. Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* replace usleep() for systems that don't have themDaniel Mierswa2009-08-211-0/+1
| | | | | | | | | This function is marked obsolete in POSIX.1-2001 and removed in POSIX.1-2008. Conditionally replaced with nanosleep(). Signed-off-by: Daniel Mierswa <impulze@impulze.org>
* tailf: report inotify_add_watch() problemsKarel Zak2009-08-111-1/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: unistd.h is included more than onceKarel Zak2008-11-261-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: non-linux supportSamuel Thibault2007-12-181-0/+2
| | | | | | Include <sys/inotify.h> only when inotify_init() was detected Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
* tailf: inotify based reimplementationKarel Zak2007-12-171-83/+157
| | | | | | | | | This patch: - clean up tailf(1) code - remove stupid "for() { malloc() }" array allocation in the tailf() function - add inotify(7) support Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: opened file leaving unclosedlizf2007-10-261-0/+2
| | | | Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
* tailf: replace errs.h with libc err.hKarel Zak2007-10-181-21/+13Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: add option -n to specifying output linesLi Zefan2007-10-111-5/+27
| | | | | | | | | | | | | | It will be useful if we can print out the last n lines instead of the last 10, just like tail. There are examples: tailf -n 5 file1 tailf --lines 10 file2 tailf -20 file3 Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* tailf: clean up gcc warnings & fix use of errnoKarel Zak2007-10-111-7/+13
| | | | | | | | | | | | | | | | | Fix strict gcc warnings in tailf that come from using: ("-Wall -Wp,-D_FORTIFY_SOURCE=2") tailf.c:111: warning: ignoring return value of 'fwrite', declared with attribute warn_unused_result Also, tailf uses perror() for error reporting, but it inserts an fprintf call first, so perror() is actually reporting the result of the fprintf() call, not the failing call; change the code to print the message by using strerror() instead. Builds cleanly on x86_32 and x86_64. Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* Imported from util-linux-2.12 tarball.Karel Zak2006-12-071-0/+119