bin/75028: [patch] when following multiple files, tail(1) re-prints file names

Mikhail Teterin mi+mailmx at aldan.algebra.com
Mon Dec 13 10:10:35 PST 2004


>Number:         75028
>Category:       bin
>Synopsis:       [patch] when following multiple files, tail(1) re-prints file names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 13 18:10:31 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Mikhail Teterin
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
Virtual Estates, Inc.
>Environment:
	6.x current

>Description:

	The 6.0-current finally has the great feature in the standard tail(1) -- an ability
	to follow multiple files. Unfortunately, the current implementation re-prints the
	file-name too often -- whenever a block of lines is read from the file, even if the
	previous output was ALSO read from the same file.

>How-To-Repeat:
	Try
		tail -F /COPYRIGHT /var/log/messages

	You'll see `==> /var/log/messages <==' reprinted for each new addition to the log,
	even though the previous block of lines was also from the same log (/COPYRIGHT is not,
	usually, growing).

>Fix:

	The patch below fixes the problem above (second hunk) as well as a few
	"unused variables" warnings (hunks 1 and 3).

	[I'm using (and enjoying) this new tail on all of my machines -- 5.x and 4.x included.
	FreeBSD's veterinarians are the greatest!]

cvs diff: Diffing .
Index: forward.c
===================================================================
RCS file: /meow/ncvs/src/usr.bin/tail/forward.c,v
retrieving revision 1.35
diff -U2 -r1.35 forward.c
--- forward.c	4 Nov 2004 19:18:19 -0000	1.35
+++ forward.c	11 Nov 2004 19:32:22 -0000
@@ -96,9 +96,5 @@
 forward(FILE *fp, enum STYLE style, off_t off, struct stat *sbp)
 {
-	int ch, n, kq = -1;
-	int action = USE_SLEEP;
-	struct kevent ev[2];
-	struct stat sb2;
-	struct timespec ts;
+	int ch;
 
 	switch(style) {
@@ -249,11 +245,11 @@
 show(file_info_t *file)
 {
-    int ch, first;
+    int ch;
+    static file_info_t *last;
 
-    first = 1; 
     while ((ch = getc(file->fp)) != EOF) {
-	if (first && no_files > 1) {
+	if (last != file && no_files > 1) {
 		(void)printf("\n==> %s <==\n", file->file_name);
-		first = 0;
+		last = file;
 	}
 	if (putchar(ch) == EOF)
@@ -303,7 +299,5 @@
 	int active, i, n = -1;
 	struct stat sb2;
-	struct stat *sbp;
 	file_info_t *file;
-	long spin=1;
 	struct timespec ts;
 

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list