From mteterin@250-217.customer.cloud9.net  Mon Dec 13 18:08:12 2004
Return-Path: <mteterin@250-217.customer.cloud9.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 3742B16A4CE; Mon, 13 Dec 2004 18:08:12 +0000 (GMT)
Received: from out006.verizon.net (out006pub.verizon.net [206.46.170.106])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id A2D1243D39; Mon, 13 Dec 2004 18:08:11 +0000 (GMT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from corbulon.video-collage.com ([151.204.231.237])
          by out006.verizon.net
          (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP
          id <20041213180810.LLCK7873.out006.verizon.net@corbulon.video-collage.com>;
          Mon, 13 Dec 2004 12:08:10 -0600
Received: from 250-217.customer.cloud9.net (195-11.customer.cloud9.net [168.100.195.11])
	by corbulon.video-collage.com (8.13.1/8.13.1) with ESMTP id iBDI89Mn085335
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 13 Dec 2004 13:08:10 -0500 (EST)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from 250-217.customer.cloud9.net (mteterin@localhost [127.0.0.1])
	by 250-217.customer.cloud9.net (8.13.1/8.13.1) with ESMTP id iBDI8GGA060938
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Mon, 13 Dec 2004 13:08:16 -0500 (EST)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: (from mteterin@localhost)
	by 250-217.customer.cloud9.net (8.13.1/8.13.1/Submit) id iBDI8GYj060937;
	Mon, 13 Dec 2004 13:08:16 -0500 (EST)
	(envelope-from mteterin)
Message-Id: <200412131808.iBDI8GYj060937@250-217.customer.cloud9.net>
Date: Mon, 13 Dec 2004 13:08:16 -0500 (EST)
From: Mikhail Teterin <mi+mailmx@aldan.algebra.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: paul@freebsd.org
Subject: [patch] when following multiple files, tail(1) re-prints file names
X-Send-Pr-Version: 3.113
X-GNATS-Notify: paul@FreeBSD.org

>Number:         75028
>Category:       bin
>Synopsis:       [patch] when following multiple files, tail(1) re-prints file names
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    brian
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 13 18:10:31 GMT 2004
>Closed-Date:    Mon Mar 21 13:14:42 GMT 2005
>Last-Modified:  Mon Mar 21 13:14:42 GMT 2005
>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:
State-Changed-From-To: open->closed 
State-Changed-By: brian 
State-Changed-When: Wed Jan 12 03:53:16 GMT 2005 
State-Changed-Why:  
Fix applied to -current (although the variable removal fixes were already there) 
I'll MFC in 7 days if there are no objections. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75028 
State-Changed-From-To: closed->patched 
State-Changed-By: brian 
State-Changed-When: Wed Jan 12 04:07:34 GMT 2005 
State-Changed-Why:  
Oops, I meant to change from open -> patched, not open -> closed! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75028 
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Wed Jan 12 04:08:07 GMT 2005 
Responsible-Changed-Why:  
I've applied the patch - thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75028 

From: Brian Somers <brian@FreeBSD.org>
To: Mikhail Teterin <mi@corbulon.video-collage.com>
Cc: paul@FreeBSD.org, freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/75028: [patch] when following multiple files, tail(1)
Date: Sat, 15 Jan 2005 12:55:24 +0000

 On Thu, 13 Jan 2005 18:13:17 -0500 (EST), Mikhail Teterin <mi@corbulon.video-collage.com> wrote:
 > > > > http://www.freebsd.org/cgi/query-pr.cgi?pr=75028
 > > > 
 > > > I think, there should also be a way to suppress the outputting of
 > > > file-names completely. Perhaps, with another option (-H?). For example,
 > > > when watching web-server logs, I rarely care, which of the virtual
 > > > servers log what.
 > > > 
 > > > 	-mi
 > > 
 > > Isnt' that more a case of just tailing each file as a separate tail
 > > process?
 > 
 > Separate tail(s) are not only (slightly) more resource consuming,
 > they also can not neatly cooperate in one window. The change I'm
 > talking about requires about three lines -- two of them in the
 > options-parsing area :-) Yours,
 
 Fair enough I guess the hard stuff's already there.  If you can follow
 up with a patch I'll commit it.  I wonder is there any precedent for
 this sort of option with gnu's tail...
 
 -- 
 Brian Somers                                          <brian@Awfulhak.org>
 Don't _EVER_ lose your sense of humour !               <brian@FreeBSD.org>
State-Changed-From-To: patched->closed 
State-Changed-By: brian 
State-Changed-When: Mon Mar 21 13:11:11 GMT 2005 
State-Changed-Why:  
This was MFC'd on Jan 18 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75028 
>Unformatted:
